|
Home > Archive > Unix Programming > October 2006 > fork thread & mutex
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
fork thread & mutex
|
|
|
| Hello,
I know threads are not inherited across fork(), but is it the same
behavior for mutex ?
Documentation across Google are always talking about thread and I
suppose (logically) it's the same for mutex but I wanna be sure 
thanx
| |
| Rainer Weikusat 2006-10-01, 7:25 pm |
| "stef" <stef.pellegrino@gmail.com> writes:
> I know threads are not inherited across fork(), but is it the same
> behavior for mutex ?
> Documentation across Google are always talking about thread and I
> suppose (logically) it's the same for mutex but I wanna be sure 
It isn't. The mutex is a variable which represents the states 'locked'
and 'unlocked' "somehow" and the variable does not change its value
across a fork. Further, only the thread that locked the mutex may
unlock it (which your pthreads-implementation may or may not implement
this way -- at least NPTL/Linux apparently doesn't) which means that a
mutex the child inherits locked cannot be unlocked anymore. Threads
are supposed to use pthread_atfork to register handlers to deal with
this situation if necessary.
|
|
|
|
|