1 #include "ace/OS_NS_unistd.h"
3 #include "ace/Log_Msg.h"
5 #if defined (ACE_HAS_PTHREADS) && !defined (ACE_LACKS_PTHREAD_CANCEL)
6 // Only works on Pthreads...
9 class CanceledTask
: public ACE_Task
<ACE_MT_SYNCH
>
14 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("(%t) Starting thread\n")));
16 if (this->set_cancel_mode () < 0)
21 // Put this thread in a compute loop.. no
22 // cancellation points are available.
26 int set_cancel_mode ()
28 cancel_state new_state
;
30 // Set the cancel state to asynchronous and enabled.
31 new_state
.cancelstate
= PTHREAD_CANCEL_ENABLE
;
32 new_state
.canceltype
= PTHREAD_CANCEL_ASYNCHRONOUS
;
33 if (ACE_Thread::setcancelstate (new_state
, 0) == -1)
34 ACE_ERROR_RETURN ((LM_ERROR
,
36 ACE_TEXT ("cancelstate")), -1);
41 // Listing 2 code/ch13
42 int ACE_TMAIN (int, ACE_TCHAR
*[])
47 ACE_Thread_Manager::instance ()->cancel_task (&task
, 1);
54 #else /* ACE_HAS_PTHREADS */
55 int ACE_TMAIN (int, ACE_TCHAR
*[])
57 ACE_OS::puts ("This example works on Pthreads platforms.\n");
60 #endif /* ACE_HAS_PTHREADS */