1 #include "ace/config-lite.h"
3 #if defined (ACE_HAS_THREADS)
6 #include "ace/Log_Msg.h"
7 #include "ace/OS_NS_unistd.h"
10 class HA_CommandHandler
: public ACE_Task
<ACE_MT_SYNCH
>
13 HA_CommandHandler (const char *name
) : name_ (name
)
18 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("(%t) starting up %C\n"),
22 ACE_Message_Block
*mb
= 0;
23 while (this->getq (mb
) != -1)
25 if (mb
->msg_type () == ACE_Message_Block::MB_BREAK
)
36 void process_message (ACE_Message_Block
*)
39 ACE_TEXT ("(%t) Processing message %C\n"),
41 // Simulate compute bound task.
42 for (int i
= 0; i
< 100; i
++)
51 #if !defined (ACE_THR_PRI_OTHER_MAX)
52 // This should be fixed in ACE... There's no _MAX, _MIN values for
54 #if defined (ACE_WIN32)
55 # define ACE_THR_PRI_OTHER_MAX ((ACE_THR_PRI_OTHER_DEF) + 1)
56 #elif defined (VXWORKS)
57 # define ACE_THR_PRI_OTHER_MAX 0
61 // Listing 1 code/ch13
62 int ACE_TMAIN (int, ACE_TCHAR
*[])
64 HA_CommandHandler
hp_handler ("HighPriority");
65 hp_handler
.activate (THR_NEW_LWP
| THR_JOINABLE
,
66 1, 1, ACE_THR_PRI_OTHER_MAX
);
68 HA_CommandHandler
lp_handler ("LowPriority");
69 lp_handler
.activate (THR_NEW_LWP
| THR_JOINABLE
,
70 1, 1, ACE_THR_PRI_OTHER_DEF
);
73 for (int i
= 0; i
< 100; i
++)
75 ACE_Message_Block
*mb_hp
, *mb_lp
;
78 hp_handler
.putq (mb_hp
);
79 lp_handler
.putq (mb_lp
);
82 ACE_Message_Block
stop (0, ACE_Message_Block::MB_BREAK
);
83 hp_handler
.putq (stop
.clone ());
84 lp_handler
.putq (stop
.clone ());
93 #include "ace/OS_main.h"
94 #include "ace/OS_NS_stdio.h"
96 int ACE_TMAIN (int, ACE_TCHAR
*[])
98 ACE_OS::puts (ACE_TEXT ("This example requires threads."));
102 #endif /* ACE_HAS_THREADS */