How can I obtain a global mutex?

戏子无情 提交于 2020-06-28 09:21:29

问题


I'm trying to generate shared memory in a distributed manner; I also need the solution to be cross-platform. In order to do so, I need to synchronise the initialisation of this shared memory - using a mutex.

This mutex, thus, needs to be shared.

I've taken a look at this question: Interprocess reader/writer lock with Boost

However, it suggests placing the mutex in shared memory, generated by a central process. This is the exact opposite of what I'm wanting to do. If I had this central process (which they've referred to as parent), I could simply initialise the shared memory in there.

There's also this question: Interprocess mutex with pthreads, however, the answer to this is not cross-platform

I'm trying to achieve:

try {
    getMutex(ID); 
    // I was first 
} catch
{ 
    // someone else has mutex 
}

Is this even possible to do?

来源:https://stackoverflow.com/questions/62545417/how-can-i-obtain-a-global-mutex

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