|
Boost Users : |
Subject: [Boost-users] [interprocess] named_condition.timed_wait does not wait.
From: Moritz (mokoman_at_[hidden])
Date: 2009-09-14 09:25:49
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<named_mutex> lock(mtx1);
write_sth_to_shared_memory();
flag = true;
named_condition1.notify_all();
named_condition2.wait(lock);
_process2_: (READER)
scoped_lock<named_mutex> 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);
}
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net