[linux-audio-dev] pthread_mutex_unlock

Jens M Andreasen jens.andreasen at chello.se
Thu Jan 26 15:02:45 UTC 2006


On Thu, 2006-01-26 at 11:54 +0000, James Courtier-Dutton wrote:

> On a uniprocessor machine with two threads.
> Thread A waiting for the lock.
> Thread B has the lock.
> If thread B unlocks the lock, and then locks it again, Thread A is 
> unlikely to get a chance to get the lock.

If B unlocks the mutex and A is the only thread waiting for it, then
pthread_mutex_unlock() gives the lock to A.

B can't get it back before A have had a chance to run (whenever that'll
be.)

> Thread A will only get the lock if the kernel happens to do a task 
> switch between Thread B to Thread A.

Not according to posix. Perhaps all this talk about "aquiring the lock"
is what confuses us, suggesting that A has to be competitively active to
get anything. Instead it is the running thread that giveth the lock
away ...
Again, according to posix.


-- 




More information about the Linux-audio-dev mailing list