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.cpp144
1 files changed, 0 insertions, 144 deletions
diff --git a/examples/Threads/task_five.cpp b/examples/Threads/task_five.cpp
deleted file mode 100644
index 19f1bedd2e2..00000000000
--- a/examples/Threads/task_five.cpp
+++ /dev/null
@@ -1,144 +0,0 @@
-// $Id$
-
-// Stress testing thread creation and thread cancellation using
-// ACE_Task.
-//
-// Author: Detlef Becker <Detlef.Becker@med.siemens.de>
-
-#include "ace/Service_Config.h"
-#include "ace/Thread_Manager.h"
-#include "ace/Task.h"
-
-static const int DEFAULT_TASKS = 1000;
-static size_t stack_size = // Default stack size
-#if defined (ACE_WIN32)
- 0;
-#else
- 8192;
-#endif
-
-class Test_Task : public ACE_Task<ACE_MT_SYNCH>
-{
-public:
- Test_Task (ACE_Thread_Manager *thrmgr = ACE_Service_Config::thr_mgr ());
- ~Test_Task (void) {};
-
- int open (void * = 0);
- int svc (void);
- int close (u_long);
- int shutdown (void);
- int synch (void);
-};
-
-Test_Task::Test_Task (ACE_Thread_Manager *thrmgr)
- : ACE_Task<ACE_MT_SYNCH> (thrmgr)
-{
-}
-
-int
-Test_Task::open (void *)
-{
- return this->activate (0,
- 1,
- 0,
- ACE_DEFAULT_THREAD_PRIORITY,
- -1,
- 0,
- 0,
- 0,
- &stack_size);
-}
-
-int
-Test_Task::svc (void)
-{
- while (thr_mgr_->testcancel (ACE_OS::thr_self ()) == 0)
- // Sleep for 350 msecs.
- ACE_OS::sleep (ACE_Time_Value (0, 350000));
-
- return 0;
-}
-
-int
-Test_Task::close (u_long)
-{
- ACE_DEBUG ((LM_DEBUG, "(%t) closing down\n"));
- return 0;
-}
-
-int
-Test_Task::shutdown (void)
-{
- return thr_mgr_->cancel_grp (grp_id_);
-}
-
-int
-Test_Task::synch (void)
-{
- return thr_mgr_->wait_grp (grp_id_);
-}
-
-int
-main (int argc, char *argv[])
-{
- size_t stack_size = argc > 1 ? ACE_OS::atoi (argv[1]) : stack_size;
- const int n_tasks = argc > 2 ? ACE_OS::atoi (argv[2]) : DEFAULT_TASKS;
- u_int loop_count = 0;
- u_int error_count = 0;
-
- ACE_Thread_Manager *thr_mgr = ACE_Service_Config::thr_mgr ();
-
- Test_Task *task_array;
-
- for (;;)
- {
- int i;
- 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++)
- task_array[i].open ();
-
- ACE_OS::sleep (1);
-
- ACE_DEBUG ((LM_DEBUG,
- "Cancelling Tasks, loop count = %d, error count = %d\n",
- loop_count,
- error_count));
-
- for (i = 0; i < n_tasks; i++)
- task_array[i].shutdown ();
-
- ACE_DEBUG ((LM_DEBUG,
- "Synching Tasks, loop count = %d, error count = %d\n",
- loop_count,
- error_count));
-
- for (i = 0; i < n_tasks; i++)
- if (-1 == task_array[i].synch ())
- {
- ACE_ERROR ((LM_ERROR,
- "Error in synch! loop count = %d, error count = %d\n",
- loop_count,
- error_count));
- error_count++;
- }
-
- ACE_DEBUG ((LM_DEBUG,
- "thr_mgr->wait ();! loop count = %d, error count = %d\n",
- loop_count,
- error_count));
-
- // Wait for all the threads to finish.
- thr_mgr->wait ();
-
- delete [] task_array;
- loop_count++;
- }
-
- ACE_NOTREACHED (return 0);
-}