Reputation: 1762
In windows c++ I can create a handle to event
Handle h = CreateEvent(...)
I can then set and reset that event
SetEvent(...) and ResetEvent(...)
Finally, I can OpenEvents using the command OpenEvent(...)
Is there a boost equivelent for events?
Upvotes: 7
Views: 9164
Reputation: 22416
The threadsafe Boost Signals2 library might be of use to you. The original Signals library was not thread-safe, but implemented a signals/slots framework which isn't too many miles away from the ideas of events. Since Signals2 is threadsafe, you should be able to utilize it for passing events between threads.
Upvotes: 4
Reputation:
I think you need to use boost::mutex
, boost::unique_lock
, boost::condition_variable
and possibly bool
in order to imitate Events.
You actually might need sort of WaitForSingleObject
in order to wait for an event. Might be like this:
void wait_for_user_input()
{
boost::unique_lock<boost::mutex> lock(mut);
while(!data_ready)
{
cond.wait(lock);
}
process_user_input(); // it might be not necessary to hold mutex locked here!!!
// if so just add curly braces like this:
// void wait_for_user_input()
// {
// {
// boost::unique_lock<boost::mutex> lock(mut);
// while(!data_ready) { cond.wait(lock); }
// }
// process_user_input();
// }
}
Upvotes: 6
Reputation: 29450
What you want is named_condition variable from the boost interprocess library. The main difference from windows events is that you must use them in conjunction with a named_mutex.
Note, you can use these boost interprocess primitives within a single process. I assume you need these because you are using OpenEvent (which implies sharing of the object by use of a name). If you can avoid using a name, then you can use the non-named variants from the boost thread library.
Upvotes: 0