New submission from Kristján Valur Jónsson <krist...@ccpgames.com>:

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.

----------
assignee: ronaldoussoren
components: Interpreter Core, Macintosh
files: pthread_lock.patch
keywords: needs review, patch, patch
messages: 103247
nosy: krisvale, ronaldoussoren
severity: normal
status: open
title: Fix emulated lock to be 'fair'
versions: Python 2.7
Added file: http://bugs.python.org/file16933/pthread_lock.patch

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue8410>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to