Click to See Complete Forum and Search --> : concurrent operations


brad sue
April 12th, 2009, 12:31 PM
Hi, first please pardon me if my post is in the wrong section.. correct me please.

I would like to understand how the to make 2 processes (in UNIX environment )work in parallel ( like cobegin)
and when they are done, a Unix semaphore signal is called so the a third process starts doing its operations.

say p1 (process 1) is doing a+b
say p2 (process 2) is doing d+c

when they have both finished, then p3 (process 3) starts doing its thing.

I was thinking using fork() since it creates a duplicate of the program. I am not sure it is sufficient to generate a cobegin action

Also how to use Unix semaphore to synchronize all those processes?
I want that each process has a semaphore associate with it.

Please can someone help me to clarify this issue like some kind of pseudo code?
Thank you

xander_tan
April 15th, 2009, 02:27 AM
Hi, first please pardon me if my post is in the wrong section.. correct me please.

I would like to understand how the to make 2 processes (in UNIX environment )work in parallel ( like cobegin)
and when they are done, a Unix semaphore signal is called so the a third process starts doing its operations.

say p1 (process 1) is doing a+b
say p2 (process 2) is doing d+c

when they have both finished, then p3 (process 3) starts doing its thing.

I was thinking using fork() since it creates a duplicate of the program. I am not sure it is sufficient to generate a cobegin action

Also how to use Unix semaphore to synchronize all those processes?
I want that each process has a semaphore associate with it.

Please can someone help me to clarify this issue like some kind of pseudo code?
Thank you

I guess you need only to google a little bit, you can find this: http://www.unix.com/high-level-programming/70406-synchronize-two-processes.html

However, if you are new to concurrency, I'd suggest you to use the pipe, the second example (in the link), which I usually do. Fork is very useful, for the fact that it is very simple and easy to synchronize using pipe.