summaryrefslogtreecommitdiff
path: root/examples/Threads/task_five.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'examples/Threads/task_five.cpp')
-rw-r--r--examples/Threads/task_five.cpp58
1 files changed, 16 insertions, 42 deletions
diff --git a/examples/Threads/task_five.cpp b/examples/Threads/task_five.cpp
index 479be53deac..b8d4847d9f1 100644
--- a/examples/Threads/task_five.cpp
+++ b/examples/Threads/task_five.cpp
@@ -1,45 +1,31 @@
// $Id$
-// ============================================================================
+// Stress testing thread creation and thread cancellation using
+// ACE_Task.
//
-// = LIBRARY
-// examples/Threads/
-//
-// = FILENAME
-// task_five.cpp
-//
-// = DESCRIPTION
-// Stress testing thread creation and thread cancellation using
-// ACE_Task.
-//
-// = AUTHOR
-// Author: Detlef Becker <Detlef.Becker@med.siemens.de>
-//
-// ============================================================================
-
+// Author: Detlef Becker <Detlef.Becker@med.siemens.de>
+#include "ace/Service_Config.h"
#include "ace/Thread_Manager.h"
#include "ace/Task.h"
ACE_RCSID(Threads, task_five, "$Id$")
-static const int DEFAULT_TASKS = 100;
-static const int DEFAULT_ITERATIONS = 10;
-
-// Default stack size
-static size_t default_stack_size =
+static const int DEFAULT_TASKS = 1000;
+static size_t default_stack_size = // Default stack size
#if defined (ACE_WIN32)
0;
#else
8192;
-#endif /* ACE_WIN32 */
+#endif
+
u_int loop_count = 0;
u_int error_count = 0;
class Test_Task : public ACE_Task<ACE_SYNCH>
{
public:
- Test_Task (ACE_Thread_Manager * = ACE_Thread_Manager::instance ());
+ Test_Task (ACE_Thread_Manager *thrmgr = ACE_Service_Config::thr_mgr ());
~Test_Task (void) {};
int open (void * = 0);
@@ -97,27 +83,19 @@ Test_Task::synch (void)
return thr_mgr_->wait_grp (grp_id_);
}
-static void
-work (ACE_Thread_Manager *thr_mgr,
- int n_tasks,
- size_t stack_size)
+void work (ACE_Thread_Manager *thr_mgr, int n_tasks, size_t stack_size)
{
ACE_UNUSED_ARG (stack_size);
int i;
- Test_Task *task_array;
-
- ACE_NEW (task_array,
- Test_Task[n_tasks]);
+ Test_Task *task_array = new Test_Task[n_tasks];
ACE_DEBUG ((LM_DEBUG,
"Opening Tasks, loop count = %d, error count = %d\n",
loop_count,
error_count));
- for (i = 0;
- i < n_tasks;
- i++)
+ for (i = 0; i < n_tasks; i++)
task_array[i].open ();
ACE_OS::sleep (1);
@@ -135,9 +113,7 @@ work (ACE_Thread_Manager *thr_mgr,
loop_count,
error_count));
- for (i = 0;
-
- i < n_tasks; i++)
+ for (i = 0; i < n_tasks; i++)
if (-1 == task_array[i].synch ())
{
ACE_ERROR ((LM_ERROR,
@@ -164,12 +140,10 @@ main (int argc, char *argv[])
{
size_t stack_size = argc > 1 ? ACE_OS::atoi (argv[1]) : default_stack_size;
const int n_tasks = argc > 2 ? ACE_OS::atoi (argv[2]) : DEFAULT_TASKS;
- u_int iterations = argc > 3 ? ACE_OS::atoi (argv[3]) : DEFAULT_ITERATIONS;
- for (u_int i = 0; i < iterations; i++)
- work (ACE_Thread_Manager::instance (),
- n_tasks,
- stack_size);
+ ACE_Thread_Manager *thr_mgr = ACE_Service_Config::thr_mgr ();
+ for (;;)
+ work (thr_mgr, n_tasks, stack_size);
ACE_NOTREACHED (return 0);
}