- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Does TBB include OS-portable classes for events / signals like Win32's WaitForSingleObject() / WaitForMultipleObjects(), SetEvent(), etc? I need to sleep a thread until an event is raised.
thx
thx
1 Solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
TBB provides class condition_variable. Its interface is mostly compatible with that of C++11 cond var, and TBB injects it into the namespace std.
Link Copied
5 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
TBB provides class condition_variable. Its interface is mostly compatible with that of C++11 cond var, and TBB injects it into the namespace std.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Nice thx! Btw, any example about how to simulate the WaitForMultipleObjects, pls? I see on the class definition it's really a WaitforSingleObject equivalent.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I don't know about any established patterns (anybody?), but you'll probably have to do some work on the source side to associate those "events" with a consumer, e.g., by posting something to a queue with a condition variable, like pushing instead of pulling. If the source isn't active, you'll have to run a thread to wait for events and translate them into events pushed onto the queue (notifying any consumers about their presence), which seems a bit annoying. Of course, when you're doing that, you might as well enqueue tasks instead, I suppose.
Further insights welcome!
Further insights welcome!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Btw, I wanted this to wait for 3 events ( "any" condition ). A class like this one would help a lot:
struct Event
{
//....
};
class EventList
{
public:
void Add ( const Event &e );
{
m_stlEvts.push_back(e);
}
void WaitAll ( const size_t timeInMS ); //timeInMS to wait/timeout or 0 for infinite
int WaitAny ( const size_t timeInMS ); //return the event # in the list triggered, or -1 for timeout, <-1 on error
int WaitSingle ( const size_t eventID ); //eventID=event # in the list. Return 0 on trigger, -1 on timeour, <-1 if error
private:
std::vector m_stlEvt;
};
thx
struct Event
{
//....
};
class EventList
{
public:
void Add ( const Event &e );
{
m_stlEvts.push_back(e);
}
void WaitAll ( const size_t timeInMS ); //timeInMS to wait/timeout or 0 for infinite
int WaitAny ( const size_t timeInMS ); //return the event # in the list triggered, or -1 for timeout, <-1 on error
int WaitSingle ( const size_t eventID ); //eventID=event # in the list. Return 0 on trigger, -1 on timeour, <-1 if error
private:
std::vector
};
thx
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
With a condition variable a thread waits for a signal sent through the variable. Signals can be sent at any given time under whatever logical condition(s) a program wants to use. The persistence of conditions should also be guaranteed by the program; condition variable is just a general waiting mechanism.
The basic schema to emulate WaitForMultipleObjects is the following:
- a waiting thread, when woken up, checks for all logical conditions it is interested in, and if any is not satisfied, itwaits again, otherwise proceeds;
- whenever any of the tracked conditions changes to true, the thread that made the change should notify all threads waiting on the condition variable.
The basic schema to emulate WaitForMultipleObjects is the following:
- a waiting thread, when woken up, checks for all logical conditions it is interested in, and if any is not satisfied, itwaits again, otherwise proceeds;
- whenever any of the tracked conditions changes to true, the thread that made the change should notify all threads waiting on the condition variable.
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page