Hi!

Sorry if I'm being a bit dumb, but I think you need to be a bit more specific.

What are you sharing? Memory? Files? Records in a file?

Also: Generally (in user land) a critical section usually means you are 
protecting some shared resource e.g. shared memory against concurrent access 
(not just write!) Within a process, across threads you would use a pthreads 
mutex. If you have several threads of several processes touching the same 
resource, you may need a IPC semaphore. I have never tried using both together 
under Linux (Under OS/2 it was a cinch - and I did that sort of thing.)

Another thing: Pthreads under Linux are implemented as processes (run a threaded 
process and look at ps). Do you have a design issue here? Could you thread off 
everything from one main process and stick with the pthreads API?

DAF

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().
> 
> 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.
> 
>>From what I understood, ACE has such a mechanism, but obviously, its code
> is far too #ifdef'ed to make sense of. In any case, I remember that the
> Win32 API has such a mechanism.


Similar to OS/2 - more or less. Semaphores, mutexes, muxwaits, timers and the 
whole shebang built into the kernel. Makes life easy for the application 
programmer as long as events don't come at you too fast.

DAF


> 
> Regards,
> 
>       Shlomi Fish
> 
> 
> ----------------------------------------------------------------------
> Shlomi Fish        [EMAIL PROTECTED]
> Home Page:         http://t2.technion.ac.il/~shlomif/
> Home E-mail:       [EMAIL PROTECTED]
> 
> "Let's suppose you have a table with 2^n cups..."
> "Wait a second - is n a natural number?"
> 
> 
> =================================================================
> 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]
> 
> 
> 



=================================================================
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]

Reply via email to