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"
8 #include "ace/Signal.h"
9 #include "ace/Sig_Handler.h"
11 // Listing 1 code/ch13
12 class SignalableTask
: public ACE_Task
<ACE_MT_SYNCH
>
15 virtual int handle_signal (int signum
, siginfo_t
* = 0, ucontext_t
* = 0)
17 if (signum
== SIGUSR1
)
20 ACE_TEXT ("(%t) received a %S signal\n"),
29 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("(%t) Starting thread\n")));
33 ACE_Message_Block
* mb
= 0;
34 ACE_Time_Value
tv (0, 1000);
35 tv
+= ACE_OS::time (0);
36 int result
= this->getq (mb
, &tv
);
37 if (result
== -1 && errno
== EWOULDBLOCK
)
43 ACE_NOTREACHED (return 0);
47 void process_message (ACE_Message_Block
*mb
);
52 SignalableTask::process_message (ACE_Message_Block
*)
57 SignalableTask::handle_alert ()
61 // Listing 2 code/ch13
62 int ACE_TMAIN (int, ACE_TCHAR
*[])
64 SignalableTask handler
;
65 handler
.activate (THR_NEW_LWP
| THR_JOINABLE
, 5);
68 sh
.register_handler (SIGUSR1
, &handler
);
72 ACE_Thread_Manager::instance () ->
73 kill_grp (handler
.grp_id (), SIGUSR1
);
80 #include "ace/OS_main.h"
81 #include "ace/OS_NS_stdio.h"
83 int ACE_TMAIN (int, ACE_TCHAR
*[])
85 ACE_OS::puts (ACE_TEXT ("This example requires threads."));
89 #endif /* ACE_HAS_THREADS */