mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-29 04:17:55 +01:00
ThreadPool fix from trunk
This commit is contained in:
@@ -191,8 +191,12 @@ void PooledThread::release()
|
|||||||
_mutex.lock();
|
_mutex.lock();
|
||||||
_pTarget = 0;
|
_pTarget = 0;
|
||||||
_mutex.unlock();
|
_mutex.unlock();
|
||||||
|
// In case of a statically allocated thread pool (such
|
||||||
|
// as the default thread pool), Windows may have already
|
||||||
|
// terminated the thread before we got here.
|
||||||
|
if (_thread.isRunning())
|
||||||
|
_targetReady.set();
|
||||||
|
|
||||||
_targetReady.set();
|
|
||||||
if (_thread.tryJoin(JOIN_TIMEOUT))
|
if (_thread.tryJoin(JOIN_TIMEOUT))
|
||||||
{
|
{
|
||||||
delete this;
|
delete this;
|
||||||
@@ -457,25 +461,26 @@ PooledThread* ThreadPool::getThread()
|
|||||||
PooledThread* pThread = 0;
|
PooledThread* pThread = 0;
|
||||||
for (ThreadVec::iterator it = _threads.begin(); !pThread && it != _threads.end(); ++it)
|
for (ThreadVec::iterator it = _threads.begin(); !pThread && it != _threads.end(); ++it)
|
||||||
{
|
{
|
||||||
if ((*it)->idle()) pThread = *it;
|
if ((*it)->idle())
|
||||||
|
pThread = *it;
|
||||||
}
|
}
|
||||||
if (!pThread)
|
if (!pThread)
|
||||||
{
|
{
|
||||||
if (_threads.size() < _maxCapacity)
|
if (_threads.size() < _maxCapacity)
|
||||||
{
|
{
|
||||||
pThread = createThread();
|
pThread = createThread();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
pThread->start();
|
pThread->start();
|
||||||
_threads.push_back(pThread);
|
_threads.push_back(pThread);
|
||||||
}
|
} catch (...)
|
||||||
catch (...)
|
{
|
||||||
{
|
delete pThread;
|
||||||
delete pThread;
|
throw;
|
||||||
throw;
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else throw NoThreadAvailableException();
|
else
|
||||||
|
throw NoThreadAvailableException();
|
||||||
}
|
}
|
||||||
pThread->activate();
|
pThread->activate();
|
||||||
return pThread;
|
return pThread;
|
||||||
|
|||||||
Reference in New Issue
Block a user