我正在尝试从子进程中使用 C++ 中的同步队列。我在 C++ () ( http://www.internetmosquito.com/2011/04/making-thread-safe-queue-in-ci.html ) 中使用这个同步队列
我修改了队列是在升压序列化,也取代了使用boost::mutex io_mutex_,而不是使用inteprocess互斥(感谢@Sehe)boost::interprocess::interprocess_mutex io_mutex_和锁定,当我改为每有行boost::mutex::scoped_lock lock(io_mutex_);到scoped_lock<interprocess_mutex> lock(io_mutex_);
template<class T>
class SynchronizedQueue
{
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive & ar, const unsigned int version)
{
ar & sQueue;
ar & io_mutex_;
ar & waitCondition;
}
... // queue implementation (see [http://www.internetmosquito.com/2011/04/making-thread-safe-queue-in-c-i.html][2])
Run Code Online (Sandbox Code Playgroud)
}
在我的测试应用程序中,我正在创建同步队列并在其中存储此类的 100 个实例:
class gps_position
{
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive & ar, const unsigned int version)
{
ar & degrees; …Run Code Online (Sandbox Code Playgroud)