Changes to attempt to silence bcc64x
[ACE_TAO.git] / ACE / examples / Threads / token.cpp
blob411b37fbdf7e94f33c3dc8ef9aba0d8bcea6f0f2
1 // Test out the ACE Token class.
3 #include "ace/OS_main.h"
4 #include "ace/Token.h"
5 #include "ace/Task.h"
6 #include "ace/OS_NS_time.h"
9 #if defined (ACE_HAS_THREADS)
11 class My_Task : public ACE_Task<ACE_MT_SYNCH>
13 public:
14 My_Task (int n);
15 virtual int svc ();
17 static void sleep_hook (void *);
19 private:
20 ACE_Token token_;
23 My_Task::My_Task (int n)
25 // Make this Task into an Active Object.
26 this->activate (THR_BOUND | THR_DETACHED, n);
28 // Wait for all the threads to exit.
29 this->thr_mgr ()->wait ();
32 void
33 My_Task::sleep_hook (void *)
35 ACE_DEBUG ((LM_ERROR, "(%u) blocking, My_Task::sleep_hook () called\n",
36 ACE_Thread::self())) ;
39 // Test out the behavior of the ACE_Token class.
41 int
42 My_Task::svc ()
44 for (size_t i = 0; i < 100; i++)
46 // Wait for up to 1 millisecond past the current time to get the token.
47 ACE_Time_Value timeout (ACE_OS::time (0), 1000);
49 if (this->token_.acquire (&My_Task::sleep_hook, 0, &timeout) == 1)
51 this->token_.acquire ();
52 this->token_.renew ();
53 this->token_.release ();
54 this->token_.release ();
56 else
57 ACE_Thread::yield ();
59 return 0;
62 int
63 ACE_TMAIN (int argc, ACE_TCHAR *argv[])
65 My_Task tasks (argc > 1 ? ACE_OS::atoi (argv[1]) : 4);
67 return 0;
69 #else
70 int
71 ACE_TMAIN (int, ACE_TCHAR *[])
73 ACE_ERROR_RETURN ((LM_ERROR, "your platform doesn't support threads\n"), -1);
75 #endif /* */