This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author kristjan.jonsson
Recipients kristjan.jonsson, ronaldoussoren
Date 2010-04-15.20:00:42
SpamBayes Score 2.0485307e-09
Marked as misclassified No
Message-id <1271361646.51.0.206027864382.issue8410@psf.upfronthosting.co.za>
In-reply-to
Content
On pthreads plaforms, if the posix_sem functions aren't available (when _POSIX_SEMAPHORES isn't defined), the python lock is implemented with a mutex and a condition variable.  This appears to be the case on Mac OS X, for example.
The problem is that this lock does not provide fairness to threads trying to acquire it.  This makes it a very poor candidate to implement the GIL, which is a lock that is held all the time, and all the threads are in constant competition to claim.
Other implementations of the python lock, such as the posix_sem based ones (linux) and Event based (MS Windows) provide fairness through that underlying synchronization primitive.

This patch fixes the "emulated semaphore" by making all competing threads wait their turn in the condition variable, thus enjoying whatever fairness that primitive provides.

I've not tested this patch for compilation since I don't have access to a mac to do that.  But the mechanism has been tested successfully on windows.

See also issue 8299, where this has been discussed at length.
History
Date User Action Args
2010-04-15 20:00:46kristjan.jonssonsetrecipients: + kristjan.jonsson, ronaldoussoren
2010-04-15 20:00:46kristjan.jonssonsetmessageid: <1271361646.51.0.206027864382.issue8410@psf.upfronthosting.co.za>
2010-04-15 20:00:44kristjan.jonssonlinkissue8410 messages
2010-04-15 20:00:43kristjan.jonssoncreate