diff options
author | schmidt <douglascraigschmidt@users.noreply.github.com> | 1998-08-25 07:17:03 +0000 |
---|---|---|
committer | schmidt <douglascraigschmidt@users.noreply.github.com> | 1998-08-25 07:17:03 +0000 |
commit | bc187f3ed1d27a0f91d4bf4f6ecf5ac69be5db64 (patch) | |
tree | f49e8fb99e8542e221451ad0db3a57358f5ce10b /examples/Threads/task_three.cpp | |
parent | 943fa25c1c89d2a30db715832dc00fbd8e8d8c4b (diff) | |
download | ATCD-bc187f3ed1d27a0f91d4bf4f6ecf5ac69be5db64.tar.gz |
*** empty log message ***
Diffstat (limited to 'examples/Threads/task_three.cpp')
-rw-r--r-- | examples/Threads/task_three.cpp | 72 |
1 files changed, 48 insertions, 24 deletions
diff --git a/examples/Threads/task_three.cpp b/examples/Threads/task_three.cpp index 5a4b8f1e6e3..b6305330195 100644 --- a/examples/Threads/task_three.cpp +++ b/examples/Threads/task_three.cpp @@ -1,10 +1,9 @@ // $Id$ -// Exercise more tests for the ACE Tasks. This also shows off some -// Interesting uses of the ACE Log_Msg's ability to print to ostreams. -// BTW, make sure that you set the out_stream in *every* thread that -// you want to have write to the output file, i.e.: -// +// Exercise more tests for the <ACE_Task>s. This also shows off some +// Interesting uses of the <ACE_Log_Msg>'s ability to print to +// ostreams. BTW, make sure that you set the out_stream in *every* +// thread that you want to have write to the output file, i.e.: // // if (out_stream) // { @@ -22,7 +21,7 @@ ACE_RCSID(Threads, task_three, "$Id$") #if defined (ACE_HAS_THREADS) static ofstream *out_stream = 0; - +static sig_atomic_t done = 0; static const size_t NUM_INVOCATIONS = 100; static const size_t TASK_COUNT = 130; @@ -64,14 +63,15 @@ Test_Task::~Test_Task (void) { ACE_GUARD (ACE_Thread_Mutex, ace_mon, lock_); - ACE_DEBUG ((LM_DEBUG, "Test_Task destroyed, current_count_ = %d\n", + ACE_DEBUG ((LM_DEBUG, + "Test_Task destroyed, current_count_ = %d\n", Test_Task::current_count_)); } int Test_Task::open (void *args) { - r_ = (ACE_Reactor *) args; + r_ = ACE_reinterpret_cast (ACE_Reactor *, args); return ACE_Task<ACE_MT_SYNCH>::activate (THR_NEW_LWP); } @@ -81,7 +81,8 @@ Test_Task::close (u_long) ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, lock_, -1); Test_Task::current_count_--; - ACE_DEBUG ((LM_DEBUG, "Test_Task::close () current_count_ = %d.\n", + ACE_DEBUG ((LM_DEBUG, + "Test_Task::close () current_count_ = %d.\n", Test_Task::current_count_)); return 0; } @@ -100,15 +101,19 @@ Test_Task::svc (void) { ACE_OS::thr_yield (); - if (r_->notify (this, ACE_Event_Handler::READ_MASK)) + if (r_->notify (this, ACE_Event_Handler::READ_MASK) == -1) { ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, lock_, -1); - ACE_DEBUG ((LM_DEBUG, "Test_Task: error notifying reactor!\n")); + ACE_ERROR_RETURN ((LM_ERROR, + "Test_Task: error %p!\n", + "notifying reactor"), + 0); } } - ACE_DEBUG ((LM_DEBUG, " (%t) returning from svc ()\n")); + ACE_DEBUG ((LM_DEBUG, + " (%t) returning from svc ()\n")); return 0; } @@ -140,8 +145,9 @@ dispatch (void *arg) ACE_LOG_MSG->msg_ostream (out_stream); } - ACE_DEBUG ((LM_DEBUG, " (%t) Dispatcher Thread started!\n")); - ACE_Reactor *r = (ACE_Reactor *) arg; + ACE_DEBUG ((LM_DEBUG, + " (%t) Dispatcher Thread started!\n")); + ACE_Reactor *r = ACE_reinterpret_cast (ACE_Reactor *, arg); int result; r->owner (ACE_OS::thr_self ()); @@ -149,19 +155,20 @@ dispatch (void *arg) while (1) { result = r->handle_events (); + if (result <= 0) - ACE_DEBUG ((LM_DEBUG, "Dispatch: handle_events (): %d", result)); + ACE_DEBUG ((LM_DEBUG, + "Dispatch: handle_events (): %d", + result)); } - ACE_NOTREACHED(return 0); + ACE_NOTREACHED (return 0); } extern "C" void handler (int) { - *out_stream << flush; - out_stream->close (); - ACE_OS::exit (42); + done = 1; } int @@ -170,7 +177,10 @@ main (int argc, char **) if (argc > 1) { // Send output to file. - ACE_NEW_RETURN (out_stream, ofstream ("test_task_three.out", ios::trunc|ios::out), -1); + ACE_NEW_RETURN (out_stream, + ofstream ("test_task_three.out", + ios::trunc|ios::out), + -1); ACE_LOG_MSG->set_flags (ACE_Log_Msg::OSTREAM); ACE_LOG_MSG->msg_ostream (out_stream); } @@ -197,7 +207,7 @@ main (int argc, char **) ACE_OS::sleep (3); - for (;;) + while (done == 0) { ACE_Time_Value timeout (2); @@ -205,14 +215,27 @@ main (int argc, char **) { if (errno == ETIME) { - ACE_DEBUG ((LM_DEBUG, "no activity within 2 seconds, shutting down\n")); + ACE_DEBUG ((LM_DEBUG, + "no activity within 2 seconds, shutting down\n")); break; } else - ACE_ERROR ((LM_ERROR, "%p error handling events\n", "main")); + ACE_ERROR ((LM_ERROR, + "%p error handling events\n", + "main")); } } + if (argc > 1) + { + *out_stream << flush; + out_stream->close (); + } + + // Bail out here so that we don't call the destructors for the tasks.. + ACE_OS::exit (0); + /* NOTREACHED */ + return 0; } @@ -220,7 +243,8 @@ main (int argc, char **) int main (int, char *[]) { - ACE_ERROR ((LM_ERROR, "threads not supported on this platform\n")); + ACE_ERROR ((LM_ERROR, + "threads not supported on this platform\n")); return 0; } #endif /* ACE_HAS_THREADS */ |