diff options
Diffstat (limited to 'ACE/examples/APG/ThreadPools/ThreadPool.cpp')
-rw-r--r-- | ACE/examples/APG/ThreadPools/ThreadPool.cpp | 34 |
1 files changed, 18 insertions, 16 deletions
diff --git a/ACE/examples/APG/ThreadPools/ThreadPool.cpp b/ACE/examples/APG/ThreadPools/ThreadPool.cpp index 684762efcbf..2e30c28f4c2 100644 --- a/ACE/examples/APG/ThreadPools/ThreadPool.cpp +++ b/ACE/examples/APG/ThreadPools/ThreadPool.cpp @@ -31,7 +31,8 @@ public: virtual int svc (void) { - thread_id_ = ACE_Thread::self (); + ACE_Thread_ID id; + thread_id_ = id; while (1) { ACE_Message_Block *mb = 0; @@ -55,9 +56,9 @@ public: } // Listing 2 - ACE_thread_t thread_id (void) + const ACE_Thread_ID& thread_id (void) { - return thread_id_; + return this->thread_id_; } private: @@ -78,7 +79,7 @@ private: } IManager *manager_; - ACE_thread_t thread_id_; + ACE_Thread_ID thread_id_; }; // Listing 1 code/ch16 @@ -136,15 +137,14 @@ public: int shut_down (void); - ACE_thread_t thread_id (Worker *worker); + const ACE_Thread_ID& thread_id (Worker *worker); virtual int return_to_work (Worker *worker) { ACE_GUARD_RETURN (ACE_Thread_Mutex, worker_mon, this->workers_lock_, -1); ACE_DEBUG ((LM_DEBUG, - ACE_TEXT ("(%t) Worker %d returning to work.\n"), - worker->thr_mgr ()->thr_self ())); + ACE_TEXT ("(%t) Worker %t returning to work.\n"))); this->workers_.enqueue_tail (worker); this->workers_cond_.signal (); @@ -160,7 +160,7 @@ private: -1); for (int i = 0; i < POOL_SIZE; i++) { - Worker *worker; + Worker *worker = 0; ACE_NEW_RETURN (worker, Worker (this), -1); this->workers_.enqueue_tail (worker); worker->activate (); @@ -195,12 +195,15 @@ Manager::shut_down (void) { iter.next (worker_ptr); Worker *worker = (*worker_ptr); + ACE_Thread_ID id = thread_id (worker); + char buf [65]; + id.to_string (buf); ACE_DEBUG ((LM_DEBUG, - ACE_TEXT ("(%t) Attempting shutdown of %d\n"), - thread_id (worker))); + ACE_TEXT ("(%t) Attempting shutdown of %C\n"), + buf)); // Send the hangup message. - ACE_Message_Block *mb; + ACE_Message_Block *mb = 0; ACE_NEW_RETURN (mb, ACE_Message_Block(0, @@ -213,8 +216,8 @@ Manager::shut_down (void) ACE_ASSERT (worker->msg_queue ()->is_empty ()); ACE_DEBUG ((LM_DEBUG, - ACE_TEXT ("(%t) Worker %d shut down.\n)"), - thread_id (worker))); + ACE_TEXT ("(%t) Worker %C shut down.\n"), + buf)); delete worker; } while (iter.advance ()); @@ -224,13 +227,12 @@ Manager::shut_down (void) return 0; } -ACE_thread_t +const ACE_Thread_ID& Manager::thread_id (Worker *worker) { return worker->thread_id (); } - int ACE_TMAIN (int, ACE_TCHAR *[]) { Manager tp; @@ -240,7 +242,7 @@ int ACE_TMAIN (int, ACE_TCHAR *[]) ACE_Time_Value tv; tv.msec (100); - ACE_Message_Block *mb; + ACE_Message_Block *mb = 0; for (int i = 0; i < 30; i++) { ACE_NEW_RETURN |