diff --git a/src_main/thread/pithread.cpp b/src_main/thread/pithread.cpp index e51b34ba..5780c114 100755 --- a/src_main/thread/pithread.cpp +++ b/src_main/thread/pithread.cpp @@ -212,7 +212,9 @@ PIThread::~PIThread() { bool PIThread::start(int timer_delay) { if (running_) return false; - terminating = running_ = false; + //if (terminating) waitForFinish(); + terminating = false; + running_ = true; delay_ = timer_delay; #ifndef WINDOWS pthread_attr_t attr; @@ -242,19 +244,22 @@ bool PIThread::start(int timer_delay) { if (PRIVATE->thread != 0) { #endif setPriority(priority_); - running_ = true; return true; } else { + running_ = false; PRIVATE->thread = 0; piCoutObj << "Error: Can`t start new thread:" << errorString(); } + running_ = false; return false; } bool PIThread::startOnce() { + if (terminating) waitForFinish(); if (running_) return false; - terminating = running_ = false; + terminating = false; + running_ = true; #ifndef WINDOWS pthread_attr_t attr; pthread_attr_init(&attr); @@ -263,7 +268,7 @@ bool PIThread::startOnce() { # endif pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); int ret = pthread_create(&(PRIVATE->thread), &attr, thread_function_once, this); - //piCout << "pthread_create" << PRIVATE->thread; + piCout << "pthread_create" << PRIVATE->thread; pthread_attr_destroy(&attr); if (ret == 0) { # ifdef MAC_OS @@ -283,12 +288,13 @@ bool PIThread::startOnce() { if (PRIVATE->thread != 0) { #endif setPriority(priority_); - running_ = true; return true; } else { + running_ = false; PRIVATE->thread = 0; piCoutObj << "Error: Can`t start new thread:" << errorString(); } + running_ = false; return false; } @@ -463,7 +469,7 @@ void PIThread::__thread_func__(void * t) { ct.terminating = ct.running_ = false; ct.tid_ = -1; //cout << "thread " << t << " exiting ... " << endl; - //piCout << "pthread_exit" << (ct.__privateinitializer__.p)->thread; + piCout << "pthread_exit" << (ct.__privateinitializer__.p)->thread; UNREGISTER_THREAD(&ct); PIINTROSPECTION_UNREGISTER_THREAD(ct.tid()); #ifndef WINDOWS @@ -512,7 +518,7 @@ void PIThread::__thread_func_once__(void * t) { ct.terminating = ct.running_ = false; ct.tid_ = -1; //cout << "thread " << t << " exiting ... " << endl; - //piCout << "pthread_exit" << (ct.__privateinitializer__.p)->thread; + piCout << "pthread_exit" << (ct.__privateinitializer__.p)->thread; UNREGISTER_THREAD(&ct); PIINTROSPECTION_UNREGISTER_THREAD(ct.tid()); #ifndef WINDOWS