Extension modules, Threading, and the GIL

"Martin v. Löwis" martin at v.loewis.de
Tue Dec 31 15:28:19 EST 2002


Bengt Richter wrote:
>>David is right that it does not matter for this issue how a thread is 
>>created: Python can deal with threads created through C API just as fine 
>>as with "Python threads"; Python threads are created through the very 
>>same C API.
> 
> Well, I meant if C stuff didn't use Python's C API to create a thread and
> all the good python stuff that the thread or threading modules will do for you.
> I meant C calling something like win32 API

And I meant the very same thing. There is absolutely nothing wrong in 
creating a thread thread CreateThread, and then using a Python 
interpreter in it.


> and doing something totally off to the side as far as Python was concerned.
> IWT the result of the above would be different from a C API call to e.g.,
> 
>     thread.start_new_thread(function, args[, kwargs]) 

It would not be different at all. start_new_thread uses CreateThread 
under the hoods.

> Well, what would happen if a win32 thread that had not been started with
> thread.start_new_thread or C-API equivalent, nevertheless attempted to
> acquire the lock? 

It would work just fine. The thread would either acquire it immediately, 
or block until the thread that currently holds it releases it.

Regards,
Martin




More information about the Python-list mailing list