global interpreter lock not working as it should

anton wilson anton.wilson at camotion.com
Mon Jul 29 19:20:11 EDT 2002


I'm running linux 2.4.18 and 2.4.19 with Python 2.2 and the linuxthreads 
library. 

I'm having a problem where the interpreter in ceval.c does not let threads 
run concurently. Any thread that holds the lock never gives up the lock until 
it has run to completion. In addition to my program printouts I've tested and 
found that as long as a thread needs to run, it will always reaquire the GIL 
immediately after releasing it every 10 byte codes! Of course, if a thread 
never blocks on the GIL, no other thread will ever run. And this is what is 
happening. 

However, this problem is solved by placing a explicit sched_yield between the 
calls to release the lock and to acquire the lock again in the interpreter 
loop. Then, switching works perfectly. 

What is the problem here? Any thoughts would be appreciated.


Anton




More information about the Python-list mailing list