What’s the mutex for in pthread_cond_wait()?

You might notice that you have to pass a mutex to pthread_cond_wait, when you are thinking to yourself “Why do I need a mutex when all I want to do is signal a waiting thread?”

This is one of those questions that doesn’t have an immediately obvious answer. Well, you are right that you can just use a dummy mutex and your thread will properly wake up, but if you actually want to signal the thread based on a *boolean condition* (as determined by real C executing code) then you need to pass a meaningful mutex.

Here is a really good explanation of when you would want to do that:

http://www.cs.wustl.edu/~schmidt/win32-cv-1.html

Happy reading.

By | 2010-05-31T23:03:00+00:00 May 31st, 2010|Uncategorized|4 Comments

4 Comments

  1. Marcus Klaas September 3, 2011 at 10:00 pm - Reply

    Mate.. you can’t make a blogpost with a title like that and then refer us to some big ass page with the answer in there some there..

  2. Patrick Stinson September 4, 2011 at 12:17 am - Reply

    It wasn’t to ask, but to tell. I’m glad you found it helpful.

  3. Anonymous April 2, 2012 at 9:53 pm - Reply

    Thanks man!

  4. Anonymous February 15, 2013 at 12:18 am - Reply

    worst blog ever

Leave A Comment

+ 74 = 75