2 //=============================================================================
6 * Stress testing thread creation and thread cancellation using
9 * @author Author: Detlef Becker <Detlef.Becker@med.siemens.de>
11 //=============================================================================
14 #include "ace/OS_main.h"
15 #include "ace/Thread_Manager.h"
17 #include "ace/OS_NS_unistd.h"
19 static const int DEFAULT_TASKS
= 100;
20 static const int DEFAULT_ITERATIONS
= 10;
23 static size_t default_stack_size
=
24 #if defined (ACE_WIN32)
28 #endif /* ACE_WIN32 */
30 u_int error_count
= 0;
32 class Test_Task
: public ACE_Task
<ACE_SYNCH
>
35 Test_Task (ACE_Thread_Manager
* = ACE_Thread_Manager::instance ());
38 //FUZZ: disable check_for_lack_ACE_OS
39 int open (void * = 0);
43 ///FUZZ: enable check_for_lack_ACE_OS
49 Test_Task::Test_Task (ACE_Thread_Manager
*thrmgr
)
50 : ACE_Task
<ACE_SYNCH
> (thrmgr
)
55 Test_Task::open (void *)
57 return this->activate (0,
60 ACE_DEFAULT_THREAD_PRIORITY
,
71 while (thr_mgr_
->testcancel (ACE_OS::thr_self ()) == 0)
72 // Sleep for 350 msecs.
73 ACE_OS::sleep (ACE_Time_Value (0, 350000));
79 Test_Task::close (u_long
)
81 ACE_DEBUG ((LM_DEBUG
, "(%t) closing down\n"));
86 Test_Task::shutdown ()
88 return thr_mgr_
->cancel_grp (grp_id_
);
94 return thr_mgr_
->wait_grp (grp_id_
);
98 work (ACE_Thread_Manager
*thr_mgr
,
102 ACE_UNUSED_ARG (stack_size
);
105 Test_Task
*task_array
;
110 ACE_DEBUG ((LM_DEBUG
,
111 "Opening Tasks, loop count = %d, error count = %d\n",
118 task_array
[i
].open ();
122 ACE_DEBUG ((LM_DEBUG
,
123 "Cancelling Tasks, loop count = %d, error count = %d\n",
127 for (i
= 0; i
< n_tasks
; i
++)
128 task_array
[i
].shutdown ();
130 ACE_DEBUG ((LM_DEBUG
,
131 "Synching Tasks, loop count = %d, error count = %d\n",
138 if (-1 == task_array
[i
].synch ())
140 ACE_ERROR ((LM_ERROR
,
141 "Error in synch! loop count = %d, error count = %d\n",
147 ACE_DEBUG ((LM_DEBUG
,
148 "thr_mgr->wait ();! loop count = %d, error count = %d\n",
152 // Wait for all the threads to finish.
155 delete [] task_array
;
160 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
162 size_t stack_size
= argc
> 1 ? ACE_OS::atoi (argv
[1]) : default_stack_size
;
163 const int n_tasks
= argc
> 2 ? ACE_OS::atoi (argv
[2]) : DEFAULT_TASKS
;
164 u_int iterations
= argc
> 3 ? ACE_OS::atoi (argv
[3]) : DEFAULT_ITERATIONS
;
166 for (u_int i
= 0; i
< iterations
; i
++)
167 work (ACE_Thread_Manager::instance (),