Python threading (was: Re: global interpreter lock not working as it should)
Duncan Booth
duncan at NOSPAMrcp.co.uk
Mon Aug 5 06:09:28 EDT 2002
a-steinhoff at web.de (Armin Steinhoff) wrote in
news:ddc19db7.0208050112.56a26827 at posting.google.com:
>> CHECK_STATUS("pthread_mutex_lock[1]");
>> success = thelock->locked == 0;
>> if (success) thelock->locked = 1;
>
> 'success' will always be 0 ... so why 'if(success)' ??????
> We are in a critical section !!!
success will be 1 if another thread had previously acquired this lock and
not yet released it.
> The while loop is plain nonsens and dangerous because 'thelock->mut'
> isn't acquired again!!
Have you read the documentation for pthread_cond_wait? It acquires the
lock.
>
>> while ( thelock->locked ) {
>> status = pthread_cond_wait(&thelock->lock_released,
>> &thelock->mut);
>> CHECK_STATUS("pthread_cond_wait");
>
> After calling pthread_cond_wait() the mutex 'thelock->mut' will be
> released!
Just as well, since it has just been acquired.
> It should be possible to implement the GIL by a single condition
> variable!
How do you expect a thread to block on a simple variable? How do you expect
to ensure that a variable is tested and updated atomically?
--
Duncan Booth duncan at rcp.co.uk
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?
More information about the Python-list
mailing list