Boost logo

Boost Users :

From: Zeljko Vrba (zvrba_at_[hidden])
Date: 2007-08-30 12:24:14


On Thu, Aug 30, 2007 at 12:08:51PM -0400, frederic.mayot_at_[hidden] wrote:
> Hi,
> I'm having a problem with mutexes.
>
> In one thread T1 I have:
> while(!end)
> {
> /* TTT */
> lock lk(mutex);
> dosomethingquick();
> }
>
>
> I'm sure dosomethingquick returns but T2 can never acquires the mutex.
> If I had a timer on line /* TTT */ in T1 (sleeps for a millisecond),
> everything works fine.
>
> Can anyone understand such a behavior? Am I doing something wrong here?
>

A guess: T1 reacquires the mutex before the OS actually dispatches T2 to run.
Unlocking the mutex just makes "ready" one of threads waiting for it, but I'm
not sure that it's required that the thread be immediately dispatched it onto
(a) CPU. When you insert a volountary sleep in T1, the scheduler puts T1 to
sleep and chooses another ready thread (T2 in this case) to run.

Read on this:
http://readlist.com/lists/vger.kernel.org/linux-kernel/31/156171.html


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net