CComponentsTimer: try to fix possible uncanceled thread

This commit is contained in:
2016-12-29 21:14:58 +01:00
parent 4b4c295289
commit e9122fbc4b

View File

@@ -98,7 +98,8 @@ void CComponentsTimer::initThread()
if (res != 0){
dprintf(DEBUG_NORMAL,"\033[33m[CComponentsTimer] [%s - %d] ERROR! pthread_create\033[0m\n", __func__, __LINE__);
return;
}
}else
dprintf(DEBUG_DEBUG,"\033[33m[CComponentsTimer] [%s - %d] started thread ID:%ld \033[0m\n", __func__, __LINE__, pthread_self());
if (res == 0)
CNeutrinoApp::getInstance()->OnBeforeRestart.connect(sl_stop_timer);
@@ -111,17 +112,17 @@ void CComponentsTimer::stopThread()
while (!sl_stop_timer.empty())
sl_stop_timer.disconnect();
if(tm_thread) {
while(tm_thread) {
int thres = pthread_cancel(tm_thread);
if (thres != 0)
dprintf(DEBUG_NORMAL,"\033[33m[CComponentsTimer] [%s - %d] ERROR! pthread_cancel, [%d]\033[0m\n", __func__, __LINE__, thres);
dprintf(DEBUG_NORMAL,"\033[33m[CComponentsTimer] [%s - %d] ERROR! pthread_cancel, error [%d] %s\033[0m\n", __func__, __LINE__, thres, strerror(thres));
thres = pthread_join(tm_thread, NULL);
void* res;
thres = pthread_join(tm_thread, &res);
if (thres != 0)
dprintf(DEBUG_NORMAL, "\033[33m[CComponentsTimer] [%s - %d] ERROR! pthread_join, [%d]\033[0m\n", __func__, __LINE__, thres);
if (thres == 0)
if (res != PTHREAD_CANCELED)
dprintf(DEBUG_NORMAL, "\033[33m[CComponentsTimer] [%s - %d] ERROR! pthread_join, thread ID:%ld, error [%d] %s\033[0m\n", __func__, __LINE__, pthread_self(), thres, strerror(thres));
else
tm_thread = 0;
}
}