On 9/21/06, Steven Lumos <steven at lumos.us>
wrote:>
> With Mongrel using Sync, are there any potential problems with actions
> that start threads and use Mutex?
No. They are separate locking primitives. The fundamental algoritm
is the same between Sync (for exclusive locks) and Mutex, with regard
to locking, so they are pretty comparable there, though Sync ends up
doing a lot more work to get the same thing done, and I think there
may be potential for a race condition in Sync''s locking because of it.
I could be wrong there, too, though. I''ve not delved into that
investigation with any depth.
In unlocking, the two differ fairly significantly. Mutex pulls a
single waiting thread out of the queue of waiting threads and wakes it
up. Sync wakes every waiting thread and lets them all vie for the
lock. Sync''s approach means that when there are a lot of waiting
threads, unlocking is a lot slower with Sync. It also probably
doesn''t matter as the first threads that wake up are the ones most
likely to acquire the lock anyway, so that''s probably why Mutex
doesn''t do it that way.
Other than those basic differences, though, they are completely
compatible so long as you don''t expect a Mutex synchronize block and a
Sync synchronize block to have any effect on the other.
Kirk Haines