[Interprocess]: using condition variables with readers-writer lock (named_sharable_mutex)
Hi, I am trying to use condition variables to signify updated data in a managed_shared_memory segment. I have one "writer" and multiple "readers" of the shared state, so I am using a readers-writer lock as follows: using SharedMutex = bi::named_sharable_mutex; using ReadLock = bi::sharable_lock<SharedMutex>; using WriteLock = bi::scoped_lock<SharedMutex>; using NewEntryCondition = bi::named_condition_any; // With a "writer" block as follows: { WriteLock w_lock( sh_mut_ ); // Update the shared memory object sh_cond_.notify_all(); } // And a "reader" block as follows (many processes call the following simultaneously): { ReadLock r_lock( sh_mut_ ); sh_cond_.wait( r_lock, []() { std::cout << "checking predicate..." << std::endl; // predicate logic goes here... }); // Access object in shared memory here } Unfortunately, although the code compiles, the reader processes are never awakened from wait() and block forever. According to the following thread from 2011: http://lists.boost.org/boost-users/2011/02/66053.php "POSIX does not support condition variables with read-write locks (although I think Windows Vista does) so Interprocess does not offer any support for this." At the time, it appears named_condition_any didn't yet exist. Has the status of this changed in the last 5 years? Is there a suggested way of implementing readers-writer locks with condition variables using boost::interprocess? Thanks! -- Chris Evans Systems Engineer Azure Summit Technology, Inc. 3050 Chain Bridge Road, Suite 600 Fairfax, VA 22030
El 20/09/2016 a las 16:42, Chris Evans escribió:
Hi,
I am trying to use condition variables to signify updated data in a managed_shared_memory segment. I have one "writer" and multiple "readers" of the shared state, so I am using a readers-writer lock as follows:
...
Unfortunately, although the code compiles, the reader processes are never awakened from wait() and block forever.
Looks like a bug. named_condition_any should work with named_sharable_mutex. Please open a ticket. Best, Ion
On Wed, Sep 21, 2016 at 5:05 AM, Ion Gaztañaga
El 20/09/2016 a las 16:42, Chris Evans escribió:
Hi,
I am trying to use condition variables to signify updated data in a managed_shared_memory segment. I have one "writer" and multiple "readers" of the shared state, so I am using a readers-writer lock as follows:
...
Unfortunately, although the code compiles, the reader processes are
never awakened from wait() and block forever.
Looks like a bug. named_condition_any should work with named_sharable_mutex. Please open a ticket.
Best,
Ion _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Thanks for the suggestion. For anyone interested: I've opened a ticket and included a small example demonstrating the behavior. https://svn.boost.org/trac/boost/ticket/12476 -- Chris Evans Systems Engineer Azure Summit Technology, Inc. 3050 Chain Bridge Road, Suite 600 Fairfax, VA 22030
participants (2)
-
Chris Evans
-
Ion Gaztañaga