Is there a "upgrade_to_unique_lock" for boost :: interprocess?

I am looking for a better way to efficiently exchange pieces of data between two (or more) processes in a read / write model with a writer error .

My current tests are with boost::interprocess . I created several managed_shared_memory and managed_shared_memory trying to block access to a data block using the interprocess mutex stored in shared memory.

However, even when using sharable_lock on the reader and upgradable_lock on the writer, the client will read fragmented values โ€‹โ€‹during write operations instead of locking . Performing a similar read / write setting between threads in the same process, I used upgrade_to_unique_lock to solve this problem. However, I did not find the equivalent of boost::interprocess . Does it exist?

Server (writer):

 while (1) { // Get upgrade lock on the mutex upgradable_lock <MutexType> lock(myMutex); // Need 'upgrade_to_unique_lock' here so shared readers will block until // write operation is finished. // Write values here } 

Client (reader)

 while (1) { // Get shared access sharable_lock <MutexType> lock(myMutex); // Read p1 data here -- occasionally invalid! } 

My guess is that the main question is: is the interprocess mutex even the right way to access shared memory between processes in a recording-related setup?

Note: using Boost 1.44.0

+4
source share
2 answers

All Boost.Interprocess updatable locks support updating beyond this . Definition here .

As for your broader question, I would think that this is exactly what you want. Readers can work simultaneously and you need to prevent simultaneous recording. If you cannot share shared memory to guarantee more limited access, this looks best.

+3
source

Solution by OP.

The answer, as stated in the comments on the question, is to use the unlock_upgradable_and_lock member unlock_upgradable_and_lock . If there is an analogue of boost::interprocess with upgrade_to_unique_lock , I do not know where it is located. But the writer() function can be rewritten as:

 while (1) { // Get upgrade lock on the mutex myMutex.lock_upgradable(); // Get exclusive access and block everyone else myMutex.unlock_upgradable_and_lock(); // Write values here // Unlock the mutex (and stop blocking readers) myMutex.unlock(); } 
0
source