On Tue, 22 Jan 2002, Shlomi Fish wrote:
> How can I implement a multi-threaded cross-process synchronization > mechanism? Let's assume I have several process: A, B, C, etc. Each has > several threads: A1, A2, A3, B1, B2, C1, C2, etc. A process may create a > different thread, or another process may be added in run-time using > fork(). ok. sounds like the typical multi-threadied+multi-process appliaction. > Now let's assume I want to protect a critical section so that: > 1. Only one thread can access it. > 2. If this thread accesses it, it does not interfere with the other > threads in the same process. (i.e: they are not blocked or anything) > > Likewise for an R/W Lock, a condition variable, a semaphore, etc. > > I tried using flock(), but it seems to allow only one thread out of a > single process at a time. what i don't uderstand is - why aren't the normal pthread locks good enough? you don't seem to want any inter-process locking, only inside-processs (i.e. only between the threads of a single process). the only 'gotcha' is the way fork should be used from a multi-threaded application, to avoid deadlocks due to locked mutexes (for example) being copied, in a locked state, to the newly forked process. the solution seems to be usage of pthread_atfork() - thught i find it a little cumbersome. if you mean to do soemthing else - please explain it more clearly. -- guy "For world domination - press 1, or dial 0, and please hold, for the creator." -- nob o. dy ================================================================= To unsubscribe, send mail to [EMAIL PROTECTED] with the word "unsubscribe" in the message body, e.g., run the command echo unsubscribe | mail [EMAIL PROTECTED]
