3

I am newbie in boost. I am trying to use shared memory to communicate between processes using boost.

It works perfectly on my windows using vs2010 with 4 processes sharing memory with a manager. The manager initiates the shared memory mechanism before the other processes are launched.

However, I am getting an interprocess_exception on Ubuntu 14 running inside VirtualBox. I am using boost 1.58 and intel compiler. Same code works on windows using vs2010.

struct shm_remove 
{
  shm_remove() { shared_memory_object::remove("MySharedMemory1"); }
  ~shm_remove() { shared_memory_object::remove("MySharedMemory1"); }
} cleaner;

// exception occurs in the next line 
managed_shared_memory sharedMemSegment = managed_shared_memory(boost::interprocess::create_only, "MySharedMemory1", 65536);

exact error : "terminate called after throwing an instance of 'boost::interprocess::interprocess_exception' what(): No such file or directory

Changing to boost::interprocess::open_or_create did not work.

Help is much appreciated.

Dipu
  • 6,999
  • 4
  • 31
  • 48
user1130254
  • 155
  • 2
  • 9
  • if you use open_or_create do you get the same error in the exeption? – Hayt Sep 09 '16 at 10:44
  • Yes , same exception , same message "No such file or directory" – user1130254 Sep 10 '16 at 04:55
  • While debugging boost I've found out that it uses FILESYSTEM_BASED shared memory and it failes in opening the file name for my shared memory. Using sudo when running my app doesn't help , is there another shared mem mechanism , not file based ? – user1130254 Sep 11 '16 at 05:54
  • non-name based only when you fork the processes I guess. have you checked those things? http://stackoverflow.com/questions/30850686/reasons-a-user-might-not-be-able-to-open-a-shared-memory-object-on-linux-systems usually for me it has been problems with /dev/shm on a virtual machine sometimes. – Hayt Sep 12 '16 at 07:23
  • Try the [XSI](https://www.boost.org/doc/libs/1_71_0/doc/html/interprocess/sharedmemorybetweenprocesses.html#interprocess.sharedmemorybetweenprocesses.sharedmemory) SYSTEM 5 shared memory for Linux. – Victor Gubin Sep 05 '19 at 15:35

1 Answers1

0

Do not use any "/" in the shared_memory_object name.

Why

The "/" character confuses boost, because on macOS the shared memory objects are stored in the file system, in a temporary folder called boost_interprocess.

In macOS 12.6.3 you can find this folder in /tmp/boost_interprocesses.

Luca Fagioli
  • 12,722
  • 5
  • 59
  • 57