2 //=============================================================================
6 * This program tests thread specific storage of data. The ACE_TSS
7 * wrapper transparently ensures that the objects of this class
8 * will be placed in thread-specific storage. All calls on
9 * ACE_TSS::operator->() are delegated to the appropriate method
10 * in the Errno class. Note that each thread of control has its
11 * own unique TSS object.
13 * @author Detlef Becker <Detlef.Becker@med.siemens.de>
15 //=============================================================================
18 #include "ace/OS_main.h"
19 #include "ace/Service_Config.h"
23 #if defined (ACE_HAS_THREADS)
25 #include "thread_specific.h"
27 static const int iterations
= 100;
30 ACE_MT (ACE_Thread_Mutex
Errno::lock_
);
33 // This is our thread-specific error handler...
34 ACE_TSS
<Errno
> TSS_Error
;
36 // Keeps track of whether Tester::close () has started.
37 // (Sun C++ 4.2 with -O3 won't link if the following is static.)
38 int close_started
= 0;
40 template <ACE_SYNCH_DECL
>
41 class Tester
: public ACE_Task
<ACE_SYNCH_USE
>
49 //FUZZ: disable check_for_lack_ACE_OS
50 /// Activate the thread.
51 virtual int open (void *args
= 0);
53 ///FUZZ: enable check_for_lack_ACE_OS
54 virtual int close (u_long args
= 0);
57 template <ACE_SYNCH_DECL
> int
58 Tester
<ACE_SYNCH_USE
>::svc ()
61 "(%t) svc: setting error code to 1\n"));
64 for (int i
= 0; i
< iterations
; i
++)
65 // Print out every tenth iteration.
69 TSS_Error
->error ()));
75 template <ACE_SYNCH_DECL
> int
76 Tester
<ACE_SYNCH_USE
>::open (void *)
78 // Make this an Active Object.
79 return this->activate ();
82 template <ACE_SYNCH_DECL
>
83 int Tester
<ACE_SYNCH_USE
>::close (u_long
)
86 "(%t) close running\n"));
89 "(%t) close: setting error code to 7\n"));
92 "(%t) close: error = %d\n",
93 TSS_Error
->error ()));
99 ACE_TMAIN (int, ACE_TCHAR
*[])
101 Tester
<ACE_MT_SYNCH
> tester
;
103 ACE_DEBUG ((LM_DEBUG
,
104 "(%t) main: setting error code to 3\n"));
105 TSS_Error
->error (3);
106 ACE_DEBUG ((LM_DEBUG
,
107 "(%t) main: error = %d\n",
108 TSS_Error
->error ()));
110 // Spawn off a thread and make test an Active Object.
113 // Keep looping until <Tester::close> is called.
114 for (int i
= 0; !close_started
; i
++) {
115 // while (!close_started)
116 if ((i
% 100) == 0) {
117 ACE_DEBUG ((LM_DEBUG
,
119 TSS_Error
->error ()));
122 ACE_DEBUG ((LM_DEBUG
,
123 "(%t) main: setting error code to 4\n"));
124 TSS_Error
->error (4);
125 ACE_DEBUG ((LM_DEBUG
,
126 "(%t) main: error = %d\n",
127 TSS_Error
->error ()));
129 // Keep looping until <Tester::close> finishes.
130 while (close_started
!= 0)
131 ACE_DEBUG ((LM_DEBUG
,
133 TSS_Error
->error ()));
138 ACE_TMAIN (int, ACE_TCHAR
*[])
140 ACE_ERROR_RETURN ((LM_ERROR
,
141 "ACE doesn't support support threads on this platform (yet)\n"),
144 #endif /* ACE_HAS_THREADS */