nrcrast
nrcrast

Reputation: 171

Boost Interprocess Map thread safety

Looking at this link right now:

http://www.boost.org/doc/libs/1_56_0/doc/html/interprocess/quick_guide.html#interprocess.quick_guide.qg_interprocess_map

I intend to use this to map memory between processes on a UNIX system. Do I have to implement my own protection for multiple processes writing/reading, or is it already built in? The docs seem unclear on this aspect.

Upvotes: 2

Views: 838

Answers (1)

sehe
sehe

Reputation: 392979

You need to sycnhronize all access to the containers in shared memory.

E.g. here:

As mentioned before, the ability to shared memory between processes through memory mapped files or shared memory objects is not very useful if the access to that memory can't be effectively synchronized. This is the same problem that happens with thread-synchronization mechanisms, where heap memory and global variables are shared between threads, but the access to these resources needs to be synchronized typically through mutex and condition variables.

Also here

Using shared memory, we can avoid two data copies, but we have to synchronize the access to the shared memory segment.

Shared memory avoids this overhead, but we need to synchronize both processes

Upvotes: 2

Related Questions