Hi all,
I am fighting with the named_condition again. Currently I am using
timed_wait but it does not behave like I expected. Sometimes it is okay
(triggers on the given timeout) but sometimes it just returns
immediately false (ignoring the timeout). Can someone give me a hint
what I am doing wrong?
Thanks in advance.
Here is a simplified version of what I try to do:
using namespace boost::interprocess;
using namespace boost::posix_time;
_process1_: (WRITER)
scoped_lock lock(mtx1);
write_sth_to_shared_memory();
flag = true;
named_condition1.notify_all();
named_condition2.wait(lock);
_process2_: (READER)
scoped_lock lock(mtx2);
while (true)
{
while (!flag)
{
flag = check_flag();
// set up timeout
time_duration delay(milliseconds(200));
ptime timeout = ptime(second_clock::universal_time());
timeout += delay;
// wait
if (named_condition1.timed_wait(lock))
{
check_for_interrupt();
break;
}
else
{
check_for_interrupt();
continue;
}
}
do_some_reading_from_shared_mem();
named_condition2.notify(all);
}