threads and extension module initialization

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Fri Mar 28 17:34:36 CET 2008


En Fri, 28 Mar 2008 13:17:44 -0300, Diez B. Roggisch <deets at nospam.web.de>  
escribió:
> pianomaestro at gmail.com schrieb:

>> I have an extension module that gets initialized multiple
>> times because I am using threads.
>>
>> How can this module access global state (not per-thread state) ?
>> It needs to create a singleton.
>
> The question is very unclear.
>
> If you are after *not* initializing your module concurrently, why don't
> you just do it *once* before the threads are started? alternatively, you
> need to govern the initialization-code with a mutex - or anything  
> similar.

Ouch... The simple "if (foo!=NULL)" I posted earlier is not thread safe  
and should not be used in this situation. Do as Diez said.

-- 
Gabriel Genellina




More information about the Python-list mailing list