Is boost::interprocess::shared_ptr threadsafe (and interprocess-safe)?

前端 未结 6 2044
天涯浪人
天涯浪人 2021-01-12 13:40

I want to share data between threads, and have it automatically deleted when the last user is done with it. This seems to work, most of the time, using boost::interpro

6条回答
  •  太阳男子
    2021-01-12 14:08

    "This seems to work, most of the time, using boost::interprocess::shared_ptr in a boost::fixed_managed_shared_memory segment: but not always." If not always means that deletion don't work always: Just use a semaphore with your thread safe container. This semaphore is not improve thread safety, but you can verify and even limit how many user use the data. If semaphore is 0, then no more user, safe delete the shared data. If only one user there, this will be 1, so copy out the user-requested data, delete the shared container, then return with the copy.

提交回复
热议问题