Boost logo

Boost Users :

Subject: [Boost-users] [interprocess] named_condition wait question
From: Moritz (mokoman_at_[hidden])
Date: 2009-09-10 07:28:52


Hi,

I am using boost::interprocess::named_condition to synchronize 1-to-many
communication. The reading processes are waiting on a named_condition
that indicates the possibility to read. Problem is now that they wait
until doomsday if no one triggers notify. So they can't quit the reading
process themselves.
Now I am thinking about using timed_wait instead of wait. That means
checking some other exit-condition periodically. The question is now if
the reader can miss the notify while he is checking that exit-condition?
This is crucial to me because the readers have to notice new data in a
shared memory segment.

Thanks in advance.

Problematic code:

named_upgradable_mutex mtx;
named_condition cond;
{
  sharable_lock<named_upgradable_mutex> lock(mtx);
  while(true)
  {
    read();
    cond.wait(lock);
  }
}

Possible solution?:

named_upgradable_mutex mtx;
named_condition cond;
{
  sharable_lock<named_upgradable_mutex> lock(mtx);
  while(true)
  {
    read();
    while (true)
    {
      if (cond.timed_wait(lock, 1 second)) break;
      else check_for_thread_interruption()
    }
  }
}


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