thread wait and notify??

Please post support and help requests here.
yakovyarmo
Posts: 1
Joined: 20 Feb 2009, 01:41

thread wait and notify??

Postby yakovyarmo » 20 Feb 2009, 01:43

can any one give me an example on how to use this mechanism??

alex
Posts: 1248
Joined: 11 Jul 2006, 16:27
Location: United_States

Re: thread wait and notify??

Postby alex » 20 Feb 2009, 01:57

Like this:

Code: Select all

class MyRunnable: public Runnable
{
 public:
  void run() { _event.wait(); }
  void notify() { _event.set(); }
private:
  Event _event;
};

int main()
{
  Thread thread;
  MyRunnable r;
  thread.start(r);
  Thread::sleep(200);
  r.notify();
  thread.join();
  return 0;
}


Return to “Support”

Who is online

Users browsing this forum: No registered users and 1 guest