Message128282
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 |
|
Date |
User |
Action |
Args |
2011-02-10 11:12:41 | neologix | set | recipients:
+ neologix, gregory.p.smith, pitrou, bobbyi |
2011-02-10 11:12:41 | neologix | set | messageid: <1297336361.0.0.0693036181768.issue6721@psf.upfronthosting.co.za> |
2011-02-10 11:12:37 | neologix | link | issue6721 messages |
2011-02-10 11:12:37 | neologix | create | |
|