C++11 condition_variables 可以用来同步进程吗?

Can C++11 condition_variables be used to synchronize processes?

我正在尝试了解 C++11 的 std::condition_variable。我已阅读 cppreference.com and cplusplus.com as well as C++0x has no semaphores? How to synchronize threads?.

上的文章

我认为三篇著名文章都没有回答我的问题是: "semaphores" 可以通过 std::mutexstd::condition_variable 的组合创建(请参阅C++0x has no semaphores? How to synchronize threads?) 的答案可以像 posix 命名信号量那样用于进程之间的同步?我不清楚是否可以实现此功能,因为我没有看到创建这些对象时使用的 "sharable" 信息,例如名称。

标准C++中最接近IPC(进程间通信)的是文件io。

标准 C++ 中没有内存中的 IPC。

不,那些是为了同步一个进程中的线程,而不是进程。

进程间通信是通过共享文件实现的。进程间互斥锁或共享内存只是一个文件(例如在您的临时文件夹中创建),用于在两个进程之间交换信息(数据、锁)。 boost::interprocess 提供了一个很好的实现(它不需要任何 link,代码是动态编译的,你只需要包含它)。

要同步进程,您应该看看 boost::interprocess. It offers synchronization mechanisms. It offers an interprocess semaphore