Charles-Francois Natali <neolo...@free.fr> added the comment:

I'm not sure that releasing the mutex is enough, it can still lead to a 
segfault, as is probably the case in this issue :
http://bugs.python.org/issue11148

Quoting pthread_atfork man page :

To understand the purpose of pthread_atfork, recall that fork duplicates the 
whole memory space, including mutexes in their current locking state, but only 
the calling thread: other threads are not running in the child process. The 
mutexes are not usable after the fork and must be initialized with 
pthread_mutex_init in the child process. This is a limitation of the current 
implementation and might or might not be present in future versions.

To avoid this, install handlers with pthread_atfork as follows: have the 
prepare handler lock the mutexes (in locking order), and the parent handler 
unlock the mutexes. The child handler should reset the mutexes using 
pthread_mutex_init, as well as any other synchronization objects such as 
condition variables.

Locking the global mutexes before the fork ensures that all other threads are 
locked out of the critical regions of code protected by those mutexes. Thus 
when fork takes a snapshot of the parent's address space, that snapshot will 
copy valid, stable data. Resetting the synchronization objects in the child 
process will ensure they are properly cleansed of any artifacts from the 
threading subsystem of the parent process. For example, a mutex may inherit a 
wait queue of threads waiting for the lock; this wait queue makes no sense in 
the child process. Initializing the mutex takes care of this.

pthread_atfork might be worth looking into

----------
nosy: +neologix

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue6721>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to