Opened 9 years ago
Last modified 8 years ago
#8799 new Bugs
named condition notify_all does not wake up waiting process
Reported by: | Owned by: | Ion Gaztañaga | |
---|---|---|---|
Milestone: | To Be Determined | Component: | interprocess |
Version: | Boost 1.53.0 | Severity: | Problem |
Keywords: | named_condition notify_all | Cc: | peter.knafl@… |
Description
The underlying snippet never catches the notify_all() signal. Operating System used is Linux 3.5.0-17-generic.
Can anybody confirm this as a bug or am I doing something wrong?
Code snippet
#include <iostream> #include <boost/interprocess/sync/named_condition.hpp> #include <boost/interprocess/sync/named_mutex.hpp> #include <boost/interprocess/sync/scoped_lock.hpp> #include <boost/interprocess/shared_memory_object.hpp> #include <boost/interprocess/mapped_region.hpp> #include <boost/version.hpp> #include <sys/types.h> #include <sys/wait.h> using namespace std; using namespace boost::interprocess; void* consumer(void*) { cout << "Started child" << endl; named_mutex mtx(create_only, "somemutex"); named_condition signal_empty (create_only, "signal_empty"); for(;;) { cout << "Child tries to lock" << endl; scoped_lock<named_mutex> lock(mtx); cout << "Child got lock and waits" << endl; signal_empty.wait(lock); cout << "Child WOKE up" << endl; } cout << "Finished child" << endl; } void* producer(void*) { cout << "Started parent" << endl; sleep(1); named_mutex mtx(open_only, "somemutex"); named_condition signal_empty (open_only, "signal_empty"); for(;;) { cout << "Parent tries to get lock" << endl; scoped_lock<named_mutex>lock(mtx); cout << "Parent got lock and notifies" << endl; sleep(1); cout << "Parent notifies child" << endl; signal_empty.notify_all(); } } int main(int argc, char** argv) { pid_t pid = fork(); if(pid == 0) { consumer(NULL); } else { producer(NULL); } }
Application output
Started parent Started child Child tries to lock Child got lock and waits Parent tries to get lock Parent got lock and notifies Parent notifies child Parent tries to get lock Parent got lock and notifies .....
Change History (5)
comment:1 by , 9 years ago
comment:5 by , 8 years ago
Happens on windows too (visual studio 2012). Seems like it's less probable though, happens randomly after a few hours sometimes.
Note:
See TracTickets
for help on using tickets.
I can't see anything wrong in the code. Can you test it with current trunk code to see if current version also does't work?