1 #include "ace/config-lite.h"
2 #if defined (ACE_HAS_THREADS)
4 #include "ace/OS_NS_time.h"
5 #include "ace/OS_NS_unistd.h"
7 #include "ace/Log_Msg.h"
10 class CanceledTask
: public ACE_Task
<ACE_MT_SYNCH
>
15 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("(%t) starting up\n")));
17 // Cache our ACE_Thread_Manager pointer.
18 ACE_Thread_Manager
*mgr
= this->thr_mgr ();
21 if (mgr
->testcancel (mgr
->thr_self ()))
24 ACE_Message_Block
*mb
= 0;
25 ACE_Time_Value
tv (0, 1000);
26 tv
+= ACE_OS::time (0);
27 int result
= this->getq (mb
, &tv
);
28 if (result
== -1 && errno
== EWOULDBLOCK
)
36 ACE_NOTREACHED (return 0);
41 // Listing 2 code/ch13
42 int ACE_TMAIN (int, ACE_TCHAR
*[])
49 ACE_Thread_Manager::instance ()->cancel_task (&task
);
56 #include "ace/OS_main.h"
57 #include "ace/OS_NS_stdio.h"
59 int ACE_TMAIN (int, ACE_TCHAR
*[])
61 ACE_OS::puts (ACE_TEXT ("This example requires threads."));
65 #endif /* ACE_HAS_THREADS */