Subj : Re: How to test mutex? To : comp.programming.threads From : Mile Blenton Date : Wed Feb 16 2005 02:50 pm Arrive wrote: > My program runs normally even without the use of mutex. Now I have added > the mutexes, how can I test them? Or ask in another way, how to > generate/find bugs in concurrency programs? > You can try inserting calls to delay execution (sleep) before releasing mutexes and in this way generate situations where two or more threads try to lock the same mutex to see if there are any deadlocks. This is simple if you used your own wrapper around mutex lock/unlock. > The program is an simple HTTP server with multithread support for our > course project. So far I have only protected all the global variables > and the file IOs by mutex. Are there any places else I need to pay > attention to? > Make sure you don't call some function from within the locked mutex that also tries to lock that mutex. That's a sure deadlock :) For access to global variables that needs to atomic it's a good practice to access these vars through get/set wrapper funcs and lock/unlock of the mutex inside them or when using OO language to access the same vars through a container object and it's wrapper funcs so the mutex handling is located in one place. > Or any good resource on thread safe? I have tried google but didn't get > a good answer. > http://www.cis.upenn.edu/~eclewis/papers/cse00.pdf http://www.csc.ncsu.edu/faculty/rhee/clas/csc495j/MultithreadedProgrammingGuide_Solaris24.pdf http://www.codeproject.com/threads/testdeadlocks.asp http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndllpro/html/msdn_deadlock.asp http://www.latenighthacking.com/projects/multithreadedDesign.html Regards, Mario .