简体   繁体   中英

Unmapping boost shared memory

I have a code where the boost shared memory is used by a single writer and many readers.

The writer creates the shared memory, opens it with write permissions, and writes data to it from time to time.

Readers come and go all the time, each reader maps to the shared memory with read_only privileges, does what it does and than calls remove.

The problem seems to be that when a reader finishes doing whatever it is doing. It calls remove, however, remove deletes the shared_memory file for new readers and they cannot map to it.

My question is, how does a process detach from the shared memory, without removing it? There does not seem to be a detach functionality in the boost library.

You should be able to use a shared refcount.

A shared shared pointer or a semaphore to achieve this.

For Boost Interprocess, closing does not remove the mapping/shared object. Just do not call remove.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM