我有一个单一的HW接口我想从在同一工作站上的两个应用程序(过程)的使用。硬件需要一次初始化调用,然后两个应用程序使用同一个函数(在同一个库中)与HW进行许多事务。如何同步两个进程?
因此,每个应用程序应该像这样:
main()
// I don't know if another app already init'ed the HW
ret = hw_init_lock(non-blocking)
if ret = OK
// no one else has done this, I have to
init_hw()
else
//someone else has already init'ed the HW, I gotta make sure it stays that way
//as long as I'm alive
increment_hw_init_ref_counter()
hw_trans_lock(blocking)
hw_trans()
hw_trans_unlock()
....
//exit app, uninit hw if we are last out
ret = decrement_hw_init_ref_counter()
if ret == 0
uninit_hw()
exit(0)
什么机制我可以是两个应用程序之间共享锁和引用计数呼叫使用?我在想命名管道,即mkfifo()。
POSIX信号可以在不相关的进程共享,同时并行线程互斥不能。 – ephemient 2008-10-31 00:12:30