python threads and the linuxthread pthread library
anton wilson
anton.wilson at camotion.com
Mon Jul 1 16:59:15 EDT 2002
Re: python threads and the linuxthread pthread library
From: anton wilson <anton.wilson at camotion.com>
To: Tim Peters <tim.one at comcast.net>
Date: Mon, 1 Jul 2002 16:52:12 -0400
> > How do threads aquire the global interpreter lock once they are awoken?
>
> I'm not sure what you mean by "awoken". Python doesn't normally put
> threads to sleep <wink>. Threads that don't hold the GIL are normally
> blocked trying to acquire the GIL. If by "awoken" you mean "become
> unblocked", then awakening and acquiring the GIL are exactly the same thing
> -- one doesn't precede the other. The details of how the GIL gets acquired
> live inside your platform thread implementation. On Linux, Python may use
> either pthread condition variables, or POSIX semaphores, to implement the
> GIL.
I think the reason why I'm confused here is that when the
PyThread_release_lock call ias executed, it simply locks the global int lock,
changes the locked variable to 0, unlocks the global interpreter lock, and
then signals a thread waiting on the unlocked mutex condition to wake up. I
can't find where a thread that gets swapped out by the interpreter blocks
when it tries to require the lock again.
Where does a swapped out thread block?
>From thread_pthread.h:
status = pthread_mutex_lock( &thelock->mut );
CHECK_STATUS("pthread_mutex_lock[3]");
thelock->locked = 0;
status = pthread_mutex_unlock( &thelock->mut );
CHECK_STATUS("pthread_mutex_unlock[3]");
/* wake up someone (anyone, if any) waiting on the lock */
status = pthread_cond_signal( &thelock->lock_released );
CHECK_STATUS("pthread_cond_signal");
More information about the Python-list
mailing list