1 // Test out the ACE Token class.
3 #include "ace/OS_main.h"
6 #include "ace/OS_NS_time.h"
9 #if defined (ACE_HAS_THREADS)
11 class My_Task
: public ACE_Task
<ACE_MT_SYNCH
>
17 static void sleep_hook (void *);
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 ();
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.
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 ();
63 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
65 My_Task
tasks (argc
> 1 ? ACE_OS::atoi (argv
[1]) : 4);
71 ACE_TMAIN (int, ACE_TCHAR
*[])
73 ACE_ERROR_RETURN ((LM_ERROR
, "your platform doesn't support threads\n"), -1);