mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-24 09:12:28 +02:00
GH #140: Poco::Runnable threading cleanup issue
This commit is contained in:
@@ -113,7 +113,7 @@ ThreadImpl::ThreadImpl():
|
||||
|
||||
ThreadImpl::~ThreadImpl()
|
||||
{
|
||||
if (!_pData->joined)
|
||||
if (_pData->started && !_pData->joined)
|
||||
{
|
||||
pthread_detach(_pData->thread);
|
||||
}
|
||||
@@ -224,6 +224,7 @@ void ThreadImpl::startImpl(Runnable& target)
|
||||
pthread_attr_destroy(&attributes);
|
||||
throw SystemException("cannot start thread");
|
||||
}
|
||||
_pData->started = true;
|
||||
pthread_attr_destroy(&attributes);
|
||||
|
||||
if (_pData->policy == SCHED_OTHER)
|
||||
@@ -273,6 +274,7 @@ void ThreadImpl::startImpl(Callable target, void* pData)
|
||||
pthread_attr_destroy(&attributes);
|
||||
throw SystemException("cannot start thread");
|
||||
}
|
||||
_pData->started = true;
|
||||
pthread_attr_destroy(&attributes);
|
||||
|
||||
if (_pData->policy == SCHED_OTHER)
|
||||
@@ -297,6 +299,7 @@ void ThreadImpl::startImpl(Callable target, void* pData)
|
||||
|
||||
void ThreadImpl::joinImpl()
|
||||
{
|
||||
if (!_pData->started) return;
|
||||
_pData->done.wait();
|
||||
void* result;
|
||||
if (pthread_join(_pData->thread, &result))
|
||||
@@ -307,14 +310,16 @@ void ThreadImpl::joinImpl()
|
||||
|
||||
bool ThreadImpl::joinImpl(long milliseconds)
|
||||
{
|
||||
if (_pData->done.tryWait(milliseconds))
|
||||
if (_pData->started && _pData->done.tryWait(milliseconds))
|
||||
{
|
||||
void* result;
|
||||
if (pthread_join(_pData->thread, &result))
|
||||
throw SystemException("cannot join thread");
|
||||
_pData->joined = true;
|
||||
return true;
|
||||
}
|
||||
else return false;
|
||||
else if (_pData->started) return false;
|
||||
else return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user