2 //=============================================================================
6 * This example illustrates how to use the ACE tracing feature and
7 * the ACE_TRACE macro. It also shows the use of the ACE_Task_Base
8 * class running as an "active object".
10 * When adding ACE tracing to an application one option is to add
12 * #define ACE_NTRACE 0
14 * in the line above #include "ace/Log_Msg.h". That's the approach shown below.
16 * Another option is to add this line in $ACE_ROOT/ace/config.h.
17 * Note, however, that if you add the line in config.h, you need to
18 * add it *after* you've built ACE, i.e., don't build ACE with it
19 * set to 0 as then you will get all the internal ACE_TRACE calls
20 * showing up as well! In a nutshell, in this second option you
23 * 1. Build ACE without tracing (i.e., don't #define ACE_NTRACE 0 in config.h)
24 * 2. Add #define ACE_NTRACE 0 in config.h
25 * 3. Build your app with tracing.
27 * @author Douglas C. Schmidt <d.schmidt@vanderbilt.edu> and Irfan Pyarali <irfan@cs.wustl.edu>
29 //=============================================================================
35 #include "ace/OS_main.h"
36 #include "ace/Signal.h"
38 #include "ace/Trace.h"
40 class My_Task
: public ACE_Task_Base
43 My_Task (size_t depth
)
48 int recursive (size_t depth
);
52 return this->recursive (this->depth_
);
56 /// Depth of the recursion.
61 My_Task::recursive (size_t depth
)
63 ACE_TRACE ("My_Task::recursive");
66 return recursive (depth
- 1);
69 // Destructor of <ACE_Trace> automatically called.
76 ACE_TRACE ("void exithook ()");
79 "we're outta here!\n"));
83 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
85 const size_t MAX_DEPTH
= argc
== 1 ? 10 : ACE_OS::atoi (argv
[1]);
87 ACE_OS::atexit (exithook
);
90 ACE_Trace::set_nesting_indent (ACE_OS::atoi (argv
[2]));
92 ACE_TRACE ("int ACE_TMAIN (int argc, ACE_TCHAR *argv[])");
94 ACE_Sig_Action
sig1 ((ACE_SignalHandler
) ACE_Trace::start_tracing
,
96 ACE_UNUSED_ARG (sig1
);
97 ACE_Sig_Action
sig2 ((ACE_SignalHandler
) ACE_Trace::stop_tracing
,
99 ACE_UNUSED_ARG (sig2
);
101 My_Task
task (MAX_DEPTH
);
103 #if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0)
104 int n_threads
= argc
> 3 ? ACE_OS::atoi (argv
[3]) : 4;
106 if (task
.activate (THR_BOUND
| THR_DETACHED
, n_threads
) == -1)
107 ACE_ERROR_RETURN ((LM_ERROR
,
112 // Wait for all the threads to exit.
113 ACE_Thread_Manager::instance ()->wait ();
115 const int MAX_ITERATIONS
= argc
> 3 ? ACE_OS::atoi (argv
[3]) : 10;
117 for (int i
= 0; i
< MAX_ITERATIONS
; i
++)
119 #endif /* ACE_MT_SAFE */
121 // Destructor automatically called.