c++ - Struggling to get boost shared memory segments to construct -


i have code i'm trying make shared memory segment. segment managed, on end, within class. shared segment used in "bulletin board" fashion. is, 1 process write it, , many others read it. without further ado:

#include <string> #include <sys/types.h> #include <boost/interprocess/managed_shared_memory.hpp>  static const std::string shm_name("sharedmemory"); static const std::string shm_status("statusarray"); static const std::string shm_info1("mfgdata");  class manager {     u_int8_t* _status;     char* _info;      boost::interprocess::managed_shared_memory _shm;      manager()         : _shm(boost::interprocess::create_only, shm_name.c_str(), 1024)     {         // process goes out lunch on first call, it's deadlock         status = _shm.construct<u_int8_t>(shm_status.c_str()) [128] (0); // array 128 bytes, init 0         info = _shm.construct<char>(shm_info1.c_str()) [256] (0);     }  public:     ~manager() {         _shm.destroy<u_int8_t>(shm_status.c_str());         _shm.destroy<char>(shm_info1.c_str());         boost::interprocess::managed_shared_memory_object::remove(shm_name.c_str());     }      manager* builder() {         // in case previous instance abnormally terminated         boost::interprocess::managed_shared_memory_object::remove(shm_name.c_str());         return new manager(); // sort of factory pattern     } }; 

the reading have done boost website on how suggests there might deadlock. in fact, that's why put ctor private section , made builder function: that, during construction, previous instances removed. however, didn't alleviate problem.

i tried changing name of shared memory segment wouldn't in use, still, process hangs when gets lines of code.

i'm using link (as others same documentation site) model. @ point, need second set of eyes , preferably experienced eyes of boost interprocess , shared memory.

by way, program model i'm using link provided "named shared memory" program. what's quite irritating i've copied program onto linux system, built , run no trouble. missing?

thanks help, andy

the problem appears have been related not related boost @ point. asked question, , tagged thusly, because when first encountered problem, precisely hangup happening. believe hangup due blocking request of mutex buried deep within boost libraries interprocess communication. believe code construct have, putting ctor private , calling factory function, has alleviated issue.

thanks brian's great suggestion, able see in moments problem was. issue in case when opening fifo i'd made earlier, option non-blocking wasn't or'ed flags , process blocking waiting party open same pipe writing.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -