我想用boost编写一个简单的应用程序,将字符串对象传递给其他进程.它编译得很好,但是当我尝试从第二个进程打印出字符串时,以下消息被放入控制台并且第二个进程崩溃:
../boost_1_44_0/boost/interprocess/sync/posix/interprocess_recursive_mutex.hpp:107:void boost :: interprocess :: interprocess_recursive_mutex :: unlock():断言`res == 0'失败.
第一个流程代码:
shared_memory_object::remove(SHARED_MEMORY_NAME);
managed_shared_memory mshm(create_only, SHARED_MEMORY_NAME, SHARED_MEMORY_SIZE );
mshm.construct<string>( IP_STRING_NAME )("Message to other process");
string syscall(argv[0]);
std::system( (syscall+" &").c_str() ); //starting second process
Run Code Online (Sandbox Code Playgroud)
第二个流程代码:
managed_shared_memory mshm( open_or_create, SHARED_MEMORY_NAME, SHARED_MEMORY_SIZE );
std::pair<string * , size_t > p= mshm.find<string>(IP_STRING_NAME);
cout<<"string is "<<*p.first<<endl;
Run Code Online (Sandbox Code Playgroud)
如何使我的应用程序以正确的方式工作?