2

複数のプロセスが共有キューに読み書きできるように、共有メモリにオブジェクトを作成する方法を学習しようとしています。プロセスがキューに書き込むと、ブースト条件変数を使用して他のプロセスにシグナルを送ることができます。私は共有メモリ アプリケーションに詳しくないので、コードを修正してください。

私のオブジェクトは以下のようになります。

typedef boost::interprocess::vector < uint8_t > buffer_t;

struct QueueType
{
    boost::interprocess::interprocess_condition Signal;
    boost::interprocess::interprocess_mutex Mutex;
    boost::interprocess::deque < buffer_t > Queue;
};

上記のクラスのオブジェクトを割り当てるための私のコードは次のとおりです。

managed_shared_memory _shm_mem;
std::string _shm_name;
QueueType * _queue;

bool Start()
{
    bool result ( false );
    try 
    {
        _shm_mem = managed_shared_memory ( open_or_create, _shm_name.c_str(), 65536);   
        _queue = _shm_mem.find_or_construct<QueueType>("Queue")();
        if ( _queue != NULL ) 
        {
           result = true;
        }   
    }
    catch (boost::interprocess::interprocess_exception &e )
    {
        std::cout << e.what() << std::endl;
    }
    return result;
}

上記のコードを使用すると、有効な _queue オブジェクトを取得できません。

4

0 に答える 0