简体   繁体   English

两个进程之间的屏障

[英]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.当进程 1 到达屏障时,它通过发布第一个信号量来向进程 2 发出信号。 Process 2 on receiving the signal, posts the second semaphore as an acknowledgment.进程 2 收到信号后,将第二个信号量作为确认发送。

The code looks something like this...代码看起来像这样......

Proc1:进程1:

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

Proc2:过程2:

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 . Linux 实现了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.对于对pthread_barrier_init的调用,您只需指定此屏障是进程共享的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM