Boost logo

Boost Users :

From: Raider (sraider_at_[hidden])
Date: 2008-03-28 14:28:14


I'm porting WinAPI code to boost.thread. Confused converting Windows
event to boost::condition...
There are two threads, one waiting to another:

HANDLE Event; // shared
Event = CreateEvent(NULL, TRUE, FALSE, NULL);
...

void Thread1()
{
   ResetEvent(Event);
   MyCode::CreateThread2();
   if (WaitForSingleObject(Event, 500 /*ms*/) != WAIT_OBJECT_0)
     ...
}

void Thread2()
{
   SetEvent(Event);
}

My solution looks like this:

boost::condition Condition;
...

void Thread1()
{
   MyCode::CreateThread2();
   boost::mutex m;
   boost::mutex::scoped_lock l(m);
   if (!Condition.timed_wait(l, make500msdelay()))
     ...
}

void Thread2()
{
   Condition.notify_all();
}

Am I using boost::condition right way? Is `m' mutex nessesary?

--
Raider

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