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
Courtney christensen
source share