1

I want to avoid data racing in a shared memory buffer between many processes.

Question: Is possible to share a std::mutex in a linux or windows shared memory system to void data racing on this shared memory buffer between many processes? How can I achieve this?

I have the impression that I'll have data racing problems when doing the memcpy of the mutex in the shared memory buffer...

João Paulo
  • 6,300
  • 4
  • 51
  • 80
  • 9
    I don't think it's possible, as it's designed for inter-*thread* synchronization. Consider e.g. [Boost interprocess](https://www.boost.org/doc/libs/1_69_0/doc/html/interprocess.html) instead. – Some programmer dude Feb 23 '19 at 14:05
  • 2
    C++11 has no support for shared memory. Hence it doesn't matter that `std::mutex` can't be shared since you're already using platform-specific APIs, e.g. POSIX mutexes can be shared across processes using [`pthread_mutexattr_setpshared`](http://pubs.opengroup.org/onlinepubs/007904975/functions/pthread_mutexattr_getpshared.html). – rustyx Feb 23 '19 at 14:47

0 Answers0