Python threading (was: Re: global interpreter lock not working as it should)

Tim Peters tim.one at comcast.net
Mon Aug 5 12:33:26 EDT 2002


[Martin v. Löwis]
> ...
> Read the semantics of pthread_cond_wait. It requires a mutex.  Also
> notice that pthread_cond_wait may return spontaneously.  Finally,
> consider that PyThread_allocate_lock needs to support the waitflag.

There's also an historic reason for the way the pthreads lock works:  at the
time I wrote that, the pthread spec was very young and undergoing rapid
change.  At the time, a pthread mutex was never intended to be held for an
appreciable time -- it was widely believed that a busy loop was an
appropriate implementation.  For that reason, the Python code is careful
never to hold the mutex across more than just a few very small C statements.
Mutexes got fancier over the years, but that design still seems a good one.






More information about the Python-list mailing list