小编Jef*_*ste的帖子

提升消费者进程中的共享内存和同步队列问题/崩溃

我正在尝试从子进程中使用 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)

c++ queue boost shared-memory boost-mutex

1
推荐指数
1
解决办法
1751
查看次数

标签 统计

boost ×1

boost-mutex ×1

c++ ×1

queue ×1

shared-memory ×1