diff options
author | Marc Laukien <marc@zeroc.com> | 2001-09-29 05:18:18 +0000 |
---|---|---|
committer | Marc Laukien <marc@zeroc.com> | 2001-09-29 05:18:18 +0000 |
commit | 7c8680fe04e1dd27ff257809331e7c08854e9beb (patch) | |
tree | 4f22cae3d82704dfe04907eb2f22f4ec47618e6a /cpp/src/Ice/ThreadPool.cpp | |
parent | fixes (diff) | |
download | ice-7c8680fe04e1dd27ff257809331e7c08854e9beb.tar.bz2 ice-7c8680fe04e1dd27ff257809331e7c08854e9beb.tar.xz ice-7c8680fe04e1dd27ff257809331e7c08854e9beb.zip |
additional error checkpoints
Diffstat (limited to 'cpp/src/Ice/ThreadPool.cpp')
-rw-r--r-- | cpp/src/Ice/ThreadPool.cpp | 47 |
1 files changed, 39 insertions, 8 deletions
diff --git a/cpp/src/Ice/ThreadPool.cpp b/cpp/src/Ice/ThreadPool.cpp index 843dad4a5bb..cdda16ecf43 100644 --- a/cpp/src/Ice/ThreadPool.cpp +++ b/cpp/src/Ice/ThreadPool.cpp @@ -69,7 +69,7 @@ IceInternal::ThreadPool::waitUntilServerFinished() { JTCSyncT<JTCMonitorT<JTCMutex> > sync(*this); - while (_servers > 0) + while (_servers > 0 && _threadNum > 0) { try { @@ -79,6 +79,12 @@ IceInternal::ThreadPool::waitUntilServerFinished() { } } + + if (_servers > 0) + { + _instance->logger()->error("can't wait for graceful server termination in thread pool\n" + "since all threads have vanished"); + } } void @@ -86,7 +92,7 @@ IceInternal::ThreadPool::waitUntilFinished() { JTCSyncT<JTCMonitorT<JTCMutex> > sync(*this); - while (_handlers.size() > 0) + while (_handlers.size() > 0 && _threadNum > 0) { try { @@ -96,6 +102,12 @@ IceInternal::ThreadPool::waitUntilFinished() { } } + + if (_handlers.size() > 0) + { + _instance->logger()->error("can't wait for graceful application termination in thread pool\n" + "since all threads have vanished"); + } } void @@ -132,18 +144,18 @@ IceInternal::ThreadPool::ThreadPool(const InstancePtr& instance) : try { - int threadNum = 10; + _threadNum = 10; string value = _instance->properties()->getProperty("Ice.ThreadPool.Size"); if (!value.empty()) { - threadNum = atoi(value.c_str()); - if (threadNum < 1) + _threadNum = atoi(value.c_str()); + if (_threadNum < 1) { - threadNum = 1; + _threadNum = 1; } } - for (int i = 0 ; i < threadNum ; ++i) + for (int i = 0 ; i < _threadNum ; ++i) { JTCThreadHandle thread = new EventHandlerThread(this); thread->start(); @@ -366,7 +378,7 @@ IceInternal::ThreadPool::run() if(p == _handlers.end()) { ostringstream s; - s << "filedescriptor " << _lastFd << " not registered in thread pool"; + s << "filedescriptor " << _lastFd << " not registered with the thread pool"; _instance->logger()->error(s.str()); goto repeatSelect; } @@ -480,6 +492,25 @@ IceInternal::ThreadPool::EventHandlerThread::run() _pool->_instance->logger()->error("unknown exception in thread pool"); } + { + JTCSyncT<JTCMonitorT<JTCMutex> > sync(*_pool.get()); + --_pool->_threadNum; + assert(_pool->_threadNum >= 0); + + // + // The notifyAll() shouldn't be needed, *except* if one of the + // threads exits because of an exception. (Which is an error + // condition in Ice and if it happens needs to be debugged.) + // However, I call notifyAll() anyway, in all cases, using a + // "defensive" programming approach when it comes to + // multithreading. + // + if (_pool->_threadNum == 0) + { + _pool->notifyAll(); // For waitUntil...Finished() methods + } + } + _pool->promoteFollower(); _pool = 0; // Break cyclic dependency } |