From ddb8e2f3976a6c8fceebefe512a30e71c42affe2 Mon Sep 17 00:00:00 2001 From: Thilo Graf Date: Thu, 29 Dec 2016 21:14:58 +0100 Subject: [PATCH] CComponentsTimer: try to fix possible uncanceled thread Origin commit data ------------------ Commit: https://github.com/neutrino-images/ni-neutrino/commit/e9122fbc4bddbc828bba0b785c805f212e46ecd9 Author: Thilo Graf Date: 2016-12-29 (Thu, 29 Dec 2016) --- src/gui/components/cc_timer.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/gui/components/cc_timer.cpp b/src/gui/components/cc_timer.cpp index 566a829e1..11ae9b35e 100644 --- a/src/gui/components/cc_timer.cpp +++ b/src/gui/components/cc_timer.cpp @@ -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; } }