Reputation: 14428
I know pthread_cond_wait unlocks the mutex attached with it. What i would like to locate is the source code of pthread_cond_wait, and to locate unlocking the mutex code. Kindly bare if the question is silly. :). Which library do i have to download and check. I am using Ubuntu.
Upvotes: 1
Views: 642
Reputation: 49300
Another alternative would be the OpenSolaris source; granted if you're interested in the linux, i.e. glibc, @David Schwartz's answer might be more "accurate".
Upvotes: 2
Reputation: 215547
While this isn't exactly the answer to your question, the important aspect of how the mutex unlock happens is that it must be done after the condition variable structure is updated to reflect that a waiter is present. This is what the standard means when it says the function "atomically" unlocks the mutex and waits. Otherwise, the same race condition would exist as if you just unlocked the mutex yourself before calling pthread_cond_wait
: Another thread could get the mutex and modify the state on which the predicate depends after you checked the predicate (and found it false) but before you called pthread_cond_wait
. You would then miss the signal and remain waiting on the cond var, perhaps forever.
Upvotes: 0
Reputation: 182865
The pthread_cond_*
functions and pthread_mutex_*
functions are part of NPTL which is now part of glibc
on any modern Linux machine. The latest version is glibc-2.11.1
and you can find the source code on the GNU glibc download site.
Upvotes: 3