问题描述
我实现一个(POSIX一致性)系统,该系统将通过共享通信的两个进程内存。
I am implementing two processes on a LynxOS SE (POSIX conformant) system that will communicate via shared memory.
一过程将作为一个生产者,另一个是消费者。在多线程系统我的做法,这将是使用互斥和condvar(条件变量)对,与消费者等待的condvar(与调用pthread_cond_wait
)和制作它的信号(与调用pthread_cond_signal
)时,共享内存进行更新。
One process will act as a "producer" and the other a "consumer". In a multi-threaded system my approach to this would be to use a mutex and condvar (condition variable) pair, with the consumer waiting on the condvar (with pthread_cond_wait
) and the producer signalling it (with pthread_cond_signal
) when the shared memory is updated.
如何在一个多进程实现这一点,而不是多线程,架构?
How do I achieve this in a multi-process, rather than multi-threaded, architecture?
有没有的LynxOS / POSIX的方式来创建一个condvar /互斥体对,可以在进程间使用吗?结果
或者是一些其他的同步机制在这种情况下更合适?
Is there a LynxOS/POSIX way to create a condvar/mutex pair that can be used between processes?
Or is some other synchronization mechanism more appropriate in this scenario?
推荐答案
标准的方法来创建一个进程共享互斥/湿。变量是你设置pthread_mutexattr_setpshared / pthread_condattr_setpshared属性初始化它们。检查LynxOS的支持。
The standard way to create a process shared mutex/cond. variable is to initialize them with an attribute where you set pthread_mutexattr_setpshared/pthread_condattr_setpshared. Check if LynxOS supports that.
您会很自然需要把这种互斥/湿。在共享内存中的变量在某种程度上,让所有进程都可以使用它。
You'll naturally need to place such mutexes/cond. variables in shared memory somehow, so all processes can use it.
这篇关于我怎么同步访问共享内存中的LynxOS / POSIX?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!