1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
// $Id$
// ============================================================================
//
// = LIBRARY
// examples/Misc
//
// = FILENAME
// test_trace.cpp
//
// = DESCRIPTION
// This example illustrates how to use the ACE tracing feature and
// also illustrates how to redirect the output to a file.
//
// = AUTHOR
// Douglas C. Schmidt <schmidt@cs.wustl.edu> and
// Irfan Pyarali <irfan@cs.wustl.edu>
//
// ============================================================================
// Enable tracing
#define ACE_NTRACE 0
#include "ace/Thread.h"
#include "ace/Signal.h"
ACE_RCSID(Misc, test_trace, "$Id$")
static void
foo (int max_depth)
{
ACE_Trace _ ("void foo (void)",
__LINE__,
__FILE__);
if (max_depth > 0)
foo (max_depth - 1);
// Destructor automatically called.
}
int
main (int argc, char *argv[])
{
const int MAX_DEPTH = argc == 1 ? 10 : atoi (argv[1]);
if (argc > 2)
ACE_Trace::set_nesting_indent (ACE_OS::atoi (argv[2]));
ACE_Trace _ ("int main (int argc, char *argv[])",
__LINE__,
__FILE__);
// The following won't work on MVS OpenEdition...
ACE_Sig_Action sig1 ((ACE_SignalHandler) ACE_Trace::start_tracing, SIGUSR1);
ACE_UNUSED_ARG (sig1);
ACE_Sig_Action sig2 ((ACE_SignalHandler) ACE_Trace::stop_tracing, SIGUSR2);
ACE_UNUSED_ARG (sig2);
#if defined(ACE_MT_SAFE) && (ACE_MT_SAFE != 0)
int n_threads = argc > 3 ? ACE_OS::atoi (argv[3]) : 4;
if (ACE_Thread::spawn_n (n_threads, ACE_THR_FUNC (foo),
(void *) MAX_DEPTH,
THR_BOUND | THR_DETACHED) != n_threads)
ACE_ERROR_RETURN ((LM_ERROR,
"%p\n",
"spawn_n"),
-1);
ACE_OS::thr_exit (0);
#else
for (;;)
foo (MAX_DEPTH);
#endif /* ACE_MT_SAFE */
// Destructor automatically called.
return 0;
}
|