id,summary,reporter,owner,description,type,status,milestone,component,version,severity,resolution,keywords,cc 12476,Using named_condition_any with a readers-writer lock,Chris Evans ,Ion Gaztañaga,"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. Unfortunately, although the code compiles, the reader processes are never awakened from wait() and block forever. It seems named_condition_any may be incompatible with named_sharable_mutex, scoped_lock, sharable_lock, or some combination of the three. Attached is a producer and consumer process that demonstrates the behavior. Run the producer first, then run the consumer. Expected behavior: consumer process will print values for ""copy of int"" every 2 seconds (as producer updates) Observed behavior: consumer process blocks on named_condition_any::wait() and never awakens. Including the code here in case the attachments don't go through: PRODUCER: {{{ #include #include #include #include #include #include #include #include #include namespace bi = boost::interprocess; using SharedMutex = bi::named_sharable_mutex; using ReadLock = bi::sharable_lock; using WriteLock = bi::scoped_lock; using NewEntryCondition = bi::named_condition_any; constexpr char SHM_NAME[] = ""shared_mem""; constexpr char MUT_NAME[] = ""shm_mut""; constexpr char COND_NAME[] = ""shm_cond""; constexpr char CUR_INT_NAME[] = ""shm_int""; int main(int argc, char *argv[]) { // Remove the shared mem, condition variable, mutex struct shm_remove { shm_remove() { bi::shared_memory_object::remove( SHM_NAME ); } ~shm_remove() { bi::shared_memory_object::remove( SHM_NAME ); } } remover; struct mut_remove { mut_remove() { SharedMutex::remove(MUT_NAME); } ~mut_remove() { SharedMutex::remove(MUT_NAME); } } mut_remover; struct cond_remove { cond_remove() { NewEntryCondition::remove(COND_NAME); } ~cond_remove() { NewEntryCondition::remove(COND_NAME); } } cond_remover; // Create the shared mem, condition variable, mutex bi::managed_shared_memory segment(bi::create_only, SHM_NAME, 2*65536); SharedMutex sh_mut(bi::create_only, MUT_NAME); NewEntryCondition sh_cond(bi::create_only, COND_NAME); int& shared_int = *segment.construct(""shared_int"")(0); for (int i=0;;i++) { std::this_thread::sleep_for(std::chrono::seconds(2)); { WriteLock w_lock( sh_mut ); shared_int = i; std::cout << ""set shared_int to: "" << shared_int << std::endl; sh_cond.notify_all(); } } return 0; } }}} CONSUMER: {{{ #include #include #include #include #include #include #include #include #include namespace bi = boost::interprocess; using SharedMutex = bi::named_sharable_mutex; using ReadLock = bi::sharable_lock; using WriteLock = bi::scoped_lock; using NewEntryCondition = bi::named_condition_any; constexpr char SHM_NAME[] = ""shared_mem""; constexpr char MUT_NAME[] = ""shm_mut""; constexpr char COND_NAME[] = ""shm_cond""; constexpr char CUR_INT_NAME[] = ""shm_int""; int main(int argc, char *argv[]) { // Open the shared mem, condition variable, mutex bi::managed_shared_memory segment(bi::open_only, SHM_NAME); SharedMutex sh_mut(bi::open_only, MUT_NAME); NewEntryCondition sh_cond(bi::open_only, COND_NAME); int& shared_int = *segment.find(""shared_int"").first; int copy_of_int = -1; for (int i=0;;i++) { { ReadLock r_lock( sh_mut ); std::cout << ""calling named_condition_any::wait()"" << std::endl; sh_cond.wait( r_lock, [&shared_int, ©_of_int]() { std::cout << ""checking predicate..."" << std::endl; return (copy_of_int < shared_int); }); copy_of_int = shared_int; std::cout << ""copy of int = "" << copy_of_int << std::endl; } } return 0; } }}} ",Bugs,new,To Be Determined,interprocess,Boost 1.58.0,Problem,,interprocess named_condition_any,