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

前端 未结 6 2043
天涯浪人
天涯浪人 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:31

    boost::shared_ptr is not interprocess safe, so whether it is multithread safe in this context is moot. (This statement assumes that BOOST_SP_DISABLE_THREADS has not been #defined for the program's operation.)

    boost::interprocess::shared_ptr is, in its very nature, designed to be cross-process safe, as well as multithread safe in its nature. When the last reference goes out of scope, the pointed-at object can be cleaned up. Obviously, this cleaning up happens within the bounds of the shared memory segment used for the object.

    Since boost::shared_ptr uses a lock-free counting mechanism at version 1.33.0 on many platforms, it is unlikely except by the remotest of chances that cross-process deletion of an object in a shared_memory segment would succeed, and does not appear to be supported functionality by the Boost maintainers.

提交回复
热议问题