summaryrefslogtreecommitdiff
path: root/ACE/examples/Threads
diff options
context:
space:
mode:
authorAbdullah Sowayan <sowayan@users.noreply.github.com>2007-07-20 03:27:14 +0000
committerAbdullah Sowayan <sowayan@users.noreply.github.com>2007-07-20 03:27:14 +0000
commit9571e27683d36960ec889ec236cfaaa169d3d2bd (patch)
tree9a9b0af5cdb16c5498b1b73eb66f48660d7985c1 /ACE/examples/Threads
parent64ada59c715e7f5f56bd50910f4a745f30e6c2b2 (diff)
downloadATCD-9571e27683d36960ec889ec236cfaaa169d3d2bd.tar.gz
Fri Jul 20 03:22:02 UTC 2007 Abdullah Sowayan <abdullah.sowayan@lmco.com>
Diffstat (limited to 'ACE/examples/Threads')
-rw-r--r--ACE/examples/Threads/barrier2.cpp53
-rw-r--r--ACE/examples/Threads/future1.cpp3
-rw-r--r--ACE/examples/Threads/future2.cpp4
-rw-r--r--ACE/examples/Threads/manual_event.cpp2
-rw-r--r--ACE/examples/Threads/task_five.cpp4
-rw-r--r--ACE/examples/Threads/task_four.cpp34
-rw-r--r--ACE/examples/Threads/task_three.cpp43
-rw-r--r--ACE/examples/Threads/task_two.cpp3
-rw-r--r--ACE/examples/Threads/thread_pool.cpp46
-rw-r--r--ACE/examples/Threads/tss1.cpp2
-rw-r--r--ACE/examples/Threads/wfmo.cpp21
11 files changed, 126 insertions, 89 deletions
diff --git a/ACE/examples/Threads/barrier2.cpp b/ACE/examples/Threads/barrier2.cpp
index cd322b82856..3264df56c11 100644
--- a/ACE/examples/Threads/barrier2.cpp
+++ b/ACE/examples/Threads/barrier2.cpp
@@ -28,8 +28,8 @@ class Worker_Task : public ACE_Task<ACE_MT_SYNCH>
{
public:
Worker_Task (ACE_Thread_Manager *thr_mgr,
- int n_threads,
- int inp_serialize = 1);
+ int n_threads,
+ int inp_serialize = 1);
virtual int producer (void);
// produce input for workers
@@ -51,10 +51,13 @@ private:
// Iterate <n_iterations> time printing off a message and "waiting"
// for all other threads to complete this iteration.
+ //FUZZ: disable check_for_lack_ACE_OS
// = Not needed for this test.
virtual int open (void *) { return 0; }
virtual int close (u_long)
{
+ //FUZZ: enable check_for_lack_ACE_OS
+
ACE_DEBUG ((LM_DEBUG,
"(%t) in close of worker\n"));
return 0;
@@ -70,8 +73,8 @@ private:
template <class BARRIER>
Worker_Task<BARRIER>::Worker_Task (ACE_Thread_Manager *thr_mgr,
- int n_threads,
- int inp_serialize)
+ int n_threads,
+ int inp_serialize)
: ACE_Task<ACE_MT_SYNCH> (thr_mgr),
barrier_ (n_threads)
{
@@ -106,7 +109,7 @@ Worker_Task<BARRIER>::put (ACE_Message_Block *mb,
result = this->service (mb, iter++);
if (this->output (mb) < 0)
- ACE_DEBUG ((LM_DEBUG,
+ ACE_DEBUG ((LM_DEBUG,
"(%t) output not connected!\n"));
mb->release ();
@@ -154,25 +157,25 @@ Worker_Task<BARRIER>::svc (void)
int result = this->getq (mb);
if (result == -1)
- {
- ACE_ERROR ((LM_ERROR,
- "(%t) in iteration %d\n",
+ {
+ ACE_ERROR ((LM_ERROR,
+ "(%t) in iteration %d\n",
"error waiting for message in iteration",
iter));
- break;
- }
+ break;
+ }
size_t length = mb->length ();
this->service (mb,iter);
if (length == 0)
- {
- ACE_DEBUG ((LM_DEBUG,
+ {
+ ACE_DEBUG ((LM_DEBUG,
"(%t) in iteration %d got quit, exit!\n",
iter));
- mb->release ();
- break;
- }
+ mb->release ();
+ break;
+ }
this->barrier_.wait ();
this->output (mb);
@@ -201,7 +204,7 @@ Worker_Task<BARRIER>::producer (void)
-1);
if (this->input (mb) == -1)
- return -1;
+ return -1;
}
ACE_NOTREACHED (return 0);
@@ -246,25 +249,25 @@ Worker_Task<BARRIER>::input (ACE_Message_Block *mb)
// this->msg_queue ()->dump ();
for (int i = 0; i < nt_; i++)
- {
- ACE_DEBUG ((LM_DEBUG,
+ {
+ ACE_DEBUG ((LM_DEBUG,
"(%t) eof, sending block for thread=%d\n",
i + 1));
- ACE_NEW_RETURN (mb1,
+ ACE_NEW_RETURN (mb1,
ACE_Message_Block (2),
-1);
- mb1->length (0);
+ mb1->length (0);
- if (this->put (mb1) == -1)
- ACE_ERROR ((LM_ERROR,
+ if (this->put (mb1) == -1)
+ ACE_ERROR ((LM_ERROR,
"(%t) %p\n",
"put"));
#if defined (delay_put)
// this sleep helps to shutdown correctly -> was an error!
- ACE_OS::sleep (1);
+ ACE_OS::sleep (1);
#endif /* delay_put */
- }
+ }
return -1;
}
else
@@ -274,7 +277,7 @@ Worker_Task<BARRIER>::input (ACE_Message_Block *mb)
mb->wr_ptr (n);
if (this->put (mb) == -1)
- ACE_ERROR ((LM_ERROR,
+ ACE_ERROR ((LM_ERROR,
"(%t) %p\n",
"put"));
}
diff --git a/ACE/examples/Threads/future1.cpp b/ACE/examples/Threads/future1.cpp
index 7b95e549431..a73549fd36c 100644
--- a/ACE/examples/Threads/future1.cpp
+++ b/ACE/examples/Threads/future1.cpp
@@ -60,8 +60,11 @@ public:
Scheduler (const char *, Scheduler * = 0);
virtual ~Scheduler (void);
+ //FUZZ: disable check_for_lack_ACE_OS
virtual int open (void *args = 0);
virtual int close (u_long flags = 0);
+ //FUZZ: enable check_for_lack_ACE_OS
+
virtual int svc (void);
ACE_Future<u_long> work (u_long param, int count = 1);
diff --git a/ACE/examples/Threads/future2.cpp b/ACE/examples/Threads/future2.cpp
index 4bb9519ca28..b907e58ddc7 100644
--- a/ACE/examples/Threads/future2.cpp
+++ b/ACE/examples/Threads/future2.cpp
@@ -64,8 +64,10 @@ public:
Scheduler (const char *, Scheduler * = 0);
virtual ~Scheduler (void);
+ //FUZZ: disable check_for_lack_ACE_OS
virtual int open (void *args = 0);
// The method that is used to start the active object.
+ //FUZZ: enable check_for_lack_ACE_OS
// = Here are the methods exported by the class. They return an
// <ACE_Future>.
@@ -74,8 +76,10 @@ public:
void end (void);
private:
+ //FUZZ: disable check_for_lack_ACE_OS
virtual int close (u_long flags = 0);
// Should not be accessible from outside... (use end () instead).
+ //FUZZ: enable check_for_lack_ACE_OS
virtual int svc (void);
// Here the actual servicing of all requests is happening..
diff --git a/ACE/examples/Threads/manual_event.cpp b/ACE/examples/Threads/manual_event.cpp
index c168c384191..d4b37975f23 100644
--- a/ACE/examples/Threads/manual_event.cpp
+++ b/ACE/examples/Threads/manual_event.cpp
@@ -38,7 +38,9 @@ class Pseudo_Barrier
public:
Pseudo_Barrier (u_long count);
+ //FUZZ: disable check_for_lack_ACE_OS
int wait (void);
+ //FUZZ: enable check_for_lack_ACE_OS
private:
ACE_Atomic_Op <ACE_Thread_Mutex, int> counter_;
diff --git a/ACE/examples/Threads/task_five.cpp b/ACE/examples/Threads/task_five.cpp
index 8f96ee3420e..66fcee550c4 100644
--- a/ACE/examples/Threads/task_five.cpp
+++ b/ACE/examples/Threads/task_five.cpp
@@ -44,10 +44,14 @@ public:
Test_Task (ACE_Thread_Manager * = ACE_Thread_Manager::instance ());
~Test_Task (void) {};
+ //FUZZ: disable check_for_lack_ACE_OS
int open (void * = 0);
int svc (void);
int close (u_long);
+
int shutdown (void);
+ //FUZZ: enable check_for_lack_ACE_OS
+
int synch (void);
};
diff --git a/ACE/examples/Threads/task_four.cpp b/ACE/examples/Threads/task_four.cpp
index 31610d56537..7f256dcb88f 100644
--- a/ACE/examples/Threads/task_four.cpp
+++ b/ACE/examples/Threads/task_four.cpp
@@ -46,9 +46,9 @@ class Invoker_Task : public ACE_Task<ACE_MT_SYNCH>
{
public:
Invoker_Task (ACE_Thread_Manager *thr_mgr,
- size_t n_tasks,
- size_t n_threads,
- size_t n_iterations);
+ size_t n_tasks,
+ size_t n_threads,
+ size_t n_iterations);
virtual int svc (void);
// creats <n_tasks> and wait for them to finish
@@ -65,11 +65,14 @@ class Worker_Task : public ACE_Task<ACE_MT_SYNCH>
{
public:
Worker_Task (ACE_Thread_Manager *thr_mgr,
- size_t n_threads,
- size_t n_iterations);
+ size_t n_threads,
+ size_t n_iterations);
virtual int svc (void);
+
+ //FUZZ: disable check_for_lack_ACE_OS
// Does a small work...
virtual int open (void * = NULL);
+ //FUZZ: enable check_for_lack_ACE_OS
private:
static size_t workers_count_;
@@ -77,8 +80,11 @@ private:
size_t n_threads_;
size_t n_iterations_;
+ //FUZZ: disable check_for_lack_ACE_OS
// = Not needed for this test.
virtual int close (u_long);
+ //FUZZ: enable check_for_lack_ACE_OS
+
virtual int put (ACE_Message_Block *, ACE_Time_Value *) { return 0; }
};
@@ -141,9 +147,9 @@ Worker_Task::svc (void)
}
Invoker_Task::Invoker_Task (ACE_Thread_Manager *thr_mgr,
- size_t n_tasks,
- size_t n_threads,
- size_t n_iterations)
+ size_t n_tasks,
+ size_t n_threads,
+ size_t n_iterations)
: ACE_Task<ACE_MT_SYNCH> (thr_mgr),
n_tasks_ (n_tasks),
n_threads_ (n_threads),
@@ -188,13 +194,13 @@ Invoker_Task::svc (void)
task + 1));
ACE_NEW_RETURN (worker_task[task],
- Worker_Task (thr_mgr,
+ Worker_Task (thr_mgr,
n_threads_,
n_iterations_),
- -1);
+ -1);
if (worker_task[task]->open () == -1)
- ACE_ERROR_RETURN ((LM_ERROR,
+ ACE_ERROR_RETURN ((LM_ERROR,
"%p\n",
"open failed"),
-1);
@@ -264,9 +270,9 @@ ACE_TMAIN (int argc, ACE_TCHAR *argv[])
ACE_Thread_Manager invoker_manager;
Invoker_Task invoker (&invoker_manager,
- n_tasks,
- n_threads,
- n_iterations);
+ n_tasks,
+ n_threads,
+ n_iterations);
// Wait for 1 second and then suspend the invoker task
ACE_OS::sleep (1);
diff --git a/ACE/examples/Threads/task_three.cpp b/ACE/examples/Threads/task_three.cpp
index 518a3f3736a..ec7bc3ad7c3 100644
--- a/ACE/examples/Threads/task_three.cpp
+++ b/ACE/examples/Threads/task_three.cpp
@@ -38,8 +38,11 @@ public:
Test_Task (void);
~Test_Task (void);
+ //FUZZ: disable check_for_lack_ACE_OS
virtual int open (void *args = 0);
virtual int close (u_long flags = 0);
+ //FUZZ: enable check_for_lack_ACE_OS
+
virtual int svc (void);
virtual int handle_input (ACE_HANDLE fd);
@@ -62,8 +65,8 @@ Test_Task::Test_Task (void)
this->handled_ = 0;
Test_Task::current_count_++;
ACE_DEBUG ((LM_DEBUG,
- ACE_TEXT ("Test_Task constructed, current_count_ = %d\n"),
- Test_Task::current_count_));
+ ACE_TEXT ("Test_Task constructed, current_count_ = %d\n"),
+ Test_Task::current_count_));
}
Test_Task::~Test_Task (void)
@@ -72,7 +75,7 @@ Test_Task::~Test_Task (void)
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("Test_Task destroyed, current_count_ = %d\n"),
- Test_Task::current_count_));
+ Test_Task::current_count_));
}
int
@@ -90,7 +93,7 @@ Test_Task::close (u_long)
Test_Task::current_count_--;
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("Test_Task::close () current_count_ = %d.\n"),
- Test_Task::current_count_));
+ Test_Task::current_count_));
return 0;
}
@@ -109,14 +112,14 @@ Test_Task::svc (void)
ACE_OS::thr_yield ();
if (r_->notify (this, ACE_Event_Handler::READ_MASK) == -1)
- {
- ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, Lock, -1);
+ {
+ ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, Lock, -1);
- ACE_ERROR_RETURN ((LM_ERROR,
+ ACE_ERROR_RETURN ((LM_ERROR,
ACE_TEXT ("Test_Task: error %p!\n"),
ACE_TEXT ("notifying reactor")),
0);
- }
+ }
}
ACE_DEBUG ((LM_DEBUG, ACE_TEXT (" (%t) returning from svc ()\n")));
@@ -133,8 +136,8 @@ Test_Task::handle_input (ACE_HANDLE)
ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, Lock, -1);
Test_Task::done_cnt_++;
ACE_DEBUG ((LM_DEBUG,
- ACE_TEXT (" (%t) Test_Task: handle_input done_cnt_ = %d.\n"),
- Test_Task::done_cnt_));
+ ACE_TEXT (" (%t) Test_Task: handle_input done_cnt_ = %d.\n"),
+ Test_Task::done_cnt_));
}
ACE_OS::thr_yield ();
@@ -162,7 +165,7 @@ dispatch (void *arg)
result = r->handle_events ();
if (result <= 0)
- ACE_DEBUG ((LM_DEBUG,
+ ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("Dispatch: handle_events (): %d"),
result));
}
@@ -223,18 +226,18 @@ ACE_TMAIN (int argc, ACE_TCHAR **)
ACE_Time_Value timeout (2);
if (reactor1->handle_events (timeout) <= 0)
- {
- if (errno == ETIME)
- {
- ACE_DEBUG ((LM_DEBUG,
+ {
+ if (errno == ETIME)
+ {
+ ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("no activity within 2 seconds, shutting down\n")));
- break;
- }
- else
- ACE_ERROR ((LM_ERROR,
+ break;
+ }
+ else
+ ACE_ERROR ((LM_ERROR,
ACE_TEXT ("%p error handling events\n"),
ACE_TEXT ("main")));
- }
+ }
}
if (argc > 1)
diff --git a/ACE/examples/Threads/task_two.cpp b/ACE/examples/Threads/task_two.cpp
index 7243ac5b1c3..91b6de2bd1a 100644
--- a/ACE/examples/Threads/task_two.cpp
+++ b/ACE/examples/Threads/task_two.cpp
@@ -32,8 +32,11 @@ static const int default_iterations = 1000;
class Task_Test : public ACE_Task<ACE_MT_SYNCH>
{
public:
+ //FUZZ: disable check_for_lack_ACE_OS
virtual int open (void *args = 0);
virtual int close (u_long flags = 0);
+ //FUZZ: enable check_for_lack_ACE_OS
+
virtual int svc (void);
private:
diff --git a/ACE/examples/Threads/thread_pool.cpp b/ACE/examples/Threads/thread_pool.cpp
index a8e609db842..01013fee406 100644
--- a/ACE/examples/Threads/thread_pool.cpp
+++ b/ACE/examples/Threads/thread_pool.cpp
@@ -49,8 +49,10 @@ public:
// This allows the producer to pass messages to the <Thread_Pool>.
private:
+ //FUZZ: disable check_for_lack_ACE_OS
virtual int close (u_long);
// Close hook.
+ //FUZZ: enable check_for_lack_ACE_OS
};
int
@@ -62,7 +64,7 @@ Thread_Pool::close (u_long)
}
Thread_Pool::Thread_Pool (ACE_Thread_Manager *thr_mgr,
- int n_threads)
+ int n_threads)
: ACE_Task<ACE_MT_SYNCH> (thr_mgr)
{
// Create the pool of worker threads.
@@ -109,19 +111,19 @@ Thread_Pool::svc (void)
count));
if (this->getq (mb) == -1)
- {
- ACE_ERROR ((LM_ERROR,
- "(%t) in iteration %d, got result -1, exiting\n",
+ {
+ ACE_ERROR ((LM_ERROR,
+ "(%t) in iteration %d, got result -1, exiting\n",
count));
break;
- }
+ }
size_t length = mb->length ();
if (length > 0)
- ACE_DEBUG ((LM_DEBUG,
- "(%t) in iteration %d, length = %d, text = \"%*s\"\n",
- count,
+ ACE_DEBUG ((LM_DEBUG,
+ "(%t) in iteration %d, length = %d, text = \"%*s\"\n",
+ count,
length,
length - 1,
mb->rd_ptr ()));
@@ -130,15 +132,15 @@ Thread_Pool::svc (void)
mb->release ();
if (length == 0)
- {
- //FUZZ: disable check_for_NULL
- ACE_DEBUG ((LM_DEBUG,
- "(%t) in iteration %d, got NULL message, exiting\n",
- count));
- //FUZZ: enable check_for_NULL
-
- break;
- }
+ {
+ //FUZZ: disable check_for_NULL
+ ACE_DEBUG ((LM_DEBUG,
+ "(%t) in iteration %d, got NULL message, exiting\n",
+ count));
+ //FUZZ: enable check_for_NULL
+
+ break;
+ }
}
// Note that the <ACE_Task::svc_run> method automatically removes us
@@ -222,13 +224,13 @@ producer (Thread_Pool &thread_pool)
ACE_ERROR ((LM_ERROR,
" (%t) %p\n",
"put"));
- }
+ }
- ACE_DEBUG ((LM_DEBUG,
+ ACE_DEBUG ((LM_DEBUG,
"\n(%t) end loop\n"));
- // thread_pool.dump ();
+ // thread_pool.dump ();
break;
- }
+ }
}
}
@@ -255,8 +257,10 @@ ACE_TMAIN (int argc, ACE_TCHAR *argv[])
"(%t) waiting for threads to exit in Thread_Pool destructor...\n"));
// Wait for all the threads to reach their exit point.
if (thread_pool.wait () == -1)
+ //FUZZ: disable check_for_lack_ACE_OS
ACE_ERROR_RETURN ((LM_ERROR, "(%t) wait() failed\n"),
1);
+ //FUZZ: enable check_for_lack_ACE_OS
ACE_DEBUG ((LM_DEBUG,
"(%t) destroying worker tasks and exiting...\n"));
diff --git a/ACE/examples/Threads/tss1.cpp b/ACE/examples/Threads/tss1.cpp
index 783d4dc5b7a..edf1ee37164 100644
--- a/ACE/examples/Threads/tss1.cpp
+++ b/ACE/examples/Threads/tss1.cpp
@@ -61,10 +61,12 @@ public:
virtual int svc (void);
+ //FUZZ: disable check_for_lack_ACE_OS
virtual int open (void *args = 0);
// Activate the thread.
virtual int close (u_long args = 0);
+ //FUZZ: enable check_for_lack_ACE_OS
};
template <ACE_SYNCH_DECL> int
diff --git a/ACE/examples/Threads/wfmo.cpp b/ACE/examples/Threads/wfmo.cpp
index bfd451444b1..d7336d4e831 100644
--- a/ACE/examples/Threads/wfmo.cpp
+++ b/ACE/examples/Threads/wfmo.cpp
@@ -25,7 +25,10 @@ static const int MAX_ITERATIONS = 100;
class WFMO_Test : public ACE_Task <ACE_NULL_SYNCH>
{
public:
+ //FUZZ: disable check_for_lack_ACE_OS
virtual int open (void *);
+ //FUZZ: enable check_for_lack_ACE_OS
+
virtual int svc (void);
// Use two handles here..
@@ -51,7 +54,7 @@ WFMO_Test::svc (void)
while(1)
{
int result = ::WaitForMultipleObjects (2, this->sema_handles_,
- FALSE, INFINITE);
+ FALSE, INFINITE);
if (result == WAIT_OBJECT_0)
{
// Signal the other semaphore just to see if we can get
@@ -60,12 +63,12 @@ WFMO_Test::svc (void)
ACE_ASSERT (result != -1);
}
else if (result == WAIT_OBJECT_0 + 1)
- ;
+ ;
else
- {
- ACE_ERROR ((LM_ERROR, "Error in WaitForMultipleObejcts\n"));
- ACE_OS::exit (0);
- }
+ {
+ ACE_ERROR ((LM_ERROR, "Error in WaitForMultipleObejcts\n"));
+ ACE_OS::exit (0);
+ }
// semaphore_count_ will be displayed by the "main" thread.
// It's value must be 2. Note that although this is a shared
@@ -114,9 +117,9 @@ ACE_TMAIN (int argc, ACE_TCHAR *argv[])
// Add one for the other thread that was signaled.
ACE_DEBUG ((LM_DEBUG,
- "semaphore_count_ = %d (should have been %d).\n",
- wfmo_test.semaphore_count_,
- 2)); // Two semaphores should have been released.
+ "semaphore_count_ = %d (should have been %d).\n",
+ wfmo_test.semaphore_count_,
+ 2)); // Two semaphores should have been released.
}
ACE_OS::exit (0);