MetallicPriest
MetallicPriest

Reputation: 30765

Barrier between Two Processes

I want to create a barrier between two processes. For that purpose, I have used two semaphores. When Process 1 reaches the barrier, it signals Process 2 by posting the first semaphore. Process 2 on receiving the signal, posts the second semaphore as an acknowledgment.

The code looks something like this...

Proc1:

sem_post( &sem_sig );
sem_wait( &sem_ack );

Proc2:

sem_wait( &sem_sig );
sem_post( &sem_ack );

Now my question is if this method is the most efficient or is there any better technique to implement process level barriers between two processes?

Upvotes: 2

Views: 1642

Answers (1)

Jens Gustedt
Jens Gustedt

Reputation: 78923

Linux implements pthread_barrier_t. To me it looks like a perfect fit to your needs. For the call to pthread_barrier_init you'd just have to specify that this barrier is process shared.

Upvotes: 2

Related Questions