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

对着背影说爱祢 提交于 2019-12-02 05:07:14

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!