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 class SignalableTask
: public ACE_Task
<ACE_MT_SYNCH
>
14 virtual int handle_signal (int signum
, siginfo_t
* = 0, ucontext_t
* = 0)
16 if (signum
== SIGUSR1
)
19 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);
37 int result
= this->getq(mb
, &tv
);
39 if (result
== -1 && errno
== EWOULDBLOCK
)
45 ACE_NOTREACHED (return 0);
49 void process_message (ACE_Message_Block
*mb
);
53 SignalableTask::process_message (ACE_Message_Block
*)
59 SignalableTask::handle_alert ()
64 // Listing 1 code/ch13
65 int ACE_TMAIN (int, ACE_TCHAR
*[])
67 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("(%t) Main thread\n")));
68 SignalableTask handler
;
69 handler
.activate (THR_NEW_LWP
| THR_JOINABLE
, 5);
72 sh
.register_handler (SIGUSR1
, &handler
);
74 ACE_OS::sleep (1); // Allow threads to start
76 for (int i
= 0; i
< 5; i
++)
77 ACE_OS::kill (ACE_OS::getpid (), SIGUSR1
);
84 #include "ace/OS_main.h"
85 #include "ace/OS_NS_stdio.h"
87 int ACE_TMAIN (int, ACE_TCHAR
*[])
89 ACE_OS::puts (ACE_TEXT ("This example requires threads."));
93 #endif /* ACE_HAS_THREADS */