summaryrefslogtreecommitdiff
path: root/cpp/src
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/src')
-rw-r--r--cpp/src/Ice/Collector.cpp6
-rw-r--r--cpp/src/Ice/ThreadPool.cpp47
-rw-r--r--cpp/src/Ice/ThreadPool.h3
3 files changed, 47 insertions, 9 deletions
diff --git a/cpp/src/Ice/Collector.cpp b/cpp/src/Ice/Collector.cpp
index 6342739632d..a6128e2ef36 100644
--- a/cpp/src/Ice/Collector.cpp
+++ b/cpp/src/Ice/Collector.cpp
@@ -431,11 +431,14 @@ IceInternal::Collector::closeConnection()
void
IceInternal::Collector::warning(const LocalException& ex) const
{
+// TODO: Property to enable/disable the warnings below
+/*
string s("server exception:\n");
s += ex.toString();
s += "\n";
s += _transceiver->toString();
_logger->warning(s);
+*/
}
void
@@ -693,9 +696,12 @@ IceInternal::CollectorFactory::clearBacklog()
void
IceInternal::CollectorFactory::warning(const LocalException& ex) const
{
+// TODO: Property to enable/disable the warnings below
+/*
string s("server exception:\n");
s += ex.toString();
s += "\n";
s += _acceptor->toString();
_logger->warning(s);
+*/
}
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
}
diff --git a/cpp/src/Ice/ThreadPool.h b/cpp/src/Ice/ThreadPool.h
index 962bffe862d..ce438212d2d 100644
--- a/cpp/src/Ice/ThreadPool.h
+++ b/cpp/src/Ice/ThreadPool.h
@@ -72,7 +72,8 @@ private:
ThreadPoolPtr _pool;
};
friend class EventHandlerThread;
- std::vector<JTCThreadHandle> _threads;
+ std::vector<JTCThreadHandle> _threads; // Handles for all threads, running or not.
+ int _threadNum; // Number of running threads.
};
}