Re: [linux-audio-dev] pthread_mutex_unlock

From: Jens M Andreasen <jens.andreasen@email-addr-hidden>
Date: Thu Jan 26 2006 - 17:02:45 EET

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.

-- 
Received on Thu Jan 26 20:15:10 2006

This archive was generated by hypermail 2.1.8 : Thu Jan 26 2006 - 20:15:10 EET