boost::named_mutex: Safely cleaning up when last process closes

后端 未结 1 1335
小鲜肉
小鲜肉 2021-01-23 12:39

I have a resource which I need to protect access to within a process, and across multiple processes. I\'ve managed this by creating a named mutex via boost::interprocess:n

相关标签:
1条回答
  • 2021-01-23 13:29

    There isn't any reference counting supported to my knowledge.

    If you are starting or stopping your processes using for example shell script you could remove the shared memory files at start/stop from the script.

    If you have one process that is always starting first then you could use it to remove shared memory files at program start (or similarly in last stopping process at program stop).

    Another approach would be implementing reference counting yourself using shared memory - last process would delete all shared memory files. However this won't work if one of the processes crash, you could still try removing in segfault signal handler but this may not always work too.

    Update: As @sehe mentioned boost::interprocess::shared_ptr can be used for reference counting.

    0 讨论(0)
提交回复
热议问题