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

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

    As pgroke alludes to (not sure why the downvotes) the core question is whether you are accessing the same shared_ptr instance from different threads or processes.

    shared_ptr (interprocess or not) does not support this scenario, and this will not be safe.

    On the other hand, shared_ptr is designed to have multiple (thread-private, or protected from concurrent modification via some other mechanism) shared pointer instances point to the same object, and have different instances of these pointers to the same object be modified concurrently without issue.

    ::interprocess:: here is mostly a red-herring - it doesn't change the thread-safety of the pointer, just makes sure there are no internal pointers that refer to process-private memory, etc.

    So which of the two cases is it?

提交回复
热议问题