开发者

Barrier between Two Processes

开发者 https://www.devze.com 2023-03-23 15:34 出处:网络
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. Proce开发者_Sta

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. Proce开发者_StackOverflow社区ss 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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号