PIThread now wait on _endThread() when starting is really done
This commit is contained in:
@@ -533,6 +533,7 @@ PRIVATE_DEFINITION_START(PIThread)
|
|||||||
pthread_t thread = 0;
|
pthread_t thread = 0;
|
||||||
sched_param sparam;
|
sched_param sparam;
|
||||||
#endif
|
#endif
|
||||||
|
std::atomic_bool starting = {false};
|
||||||
PRIVATE_DEFINITION_END(PIThread)
|
PRIVATE_DEFINITION_END(PIThread)
|
||||||
|
|
||||||
|
|
||||||
@@ -733,6 +734,8 @@ int PIThread::priority2System(PIThread::Priority p) {
|
|||||||
bool PIThread::_startThread(void * func) {
|
bool PIThread::_startThread(void * func) {
|
||||||
terminating = false;
|
terminating = false;
|
||||||
running_ = true;
|
running_ = true;
|
||||||
|
PRIVATE->starting = true;
|
||||||
|
PIScopeExitCall ec([this] { PRIVATE->starting = false; });
|
||||||
|
|
||||||
#ifdef FREERTOS
|
#ifdef FREERTOS
|
||||||
|
|
||||||
@@ -754,6 +757,7 @@ bool PIThread::_startThread(void * func) {
|
|||||||
# else
|
# else
|
||||||
PRIVATE->thread = CreateThread(0, 0, (LPTHREAD_START_ROUTINE)func, this, 0, 0);
|
PRIVATE->thread = CreateThread(0, 0, (LPTHREAD_START_ROUTINE)func, this, 0, 0);
|
||||||
# endif
|
# endif
|
||||||
|
// piCout << "started" << PRIVATE->thread;
|
||||||
if (PRIVATE->thread != 0) {
|
if (PRIVATE->thread != 0) {
|
||||||
setPriority(priority_);
|
setPriority(priority_);
|
||||||
return true;
|
return true;
|
||||||
@@ -768,6 +772,7 @@ bool PIThread::_startThread(void * func) {
|
|||||||
// PICout(PICoutManipulators::DefaultControls) << "pthread_create" << PRIVATE->thread;
|
// PICout(PICoutManipulators::DefaultControls) << "pthread_create" << PRIVATE->thread;
|
||||||
pthread_attr_destroy(&attr);
|
pthread_attr_destroy(&attr);
|
||||||
if (ret == 0) {
|
if (ret == 0) {
|
||||||
|
// if (name().isNotEmpty()) {
|
||||||
PIString tname = name().simplified();
|
PIString tname = name().simplified();
|
||||||
tname.elide(15, 0.4f).resize(15, PIChar('\0'));
|
tname.elide(15, 0.4f).resize(15, PIChar('\0'));
|
||||||
PIByteArray tn_data = tname.toAscii();
|
PIByteArray tn_data = tname.toAscii();
|
||||||
@@ -780,6 +785,7 @@ bool PIThread::_startThread(void * func) {
|
|||||||
pthread_setname_np(PRIVATE->thread, (const char *)tn_data.data());
|
pthread_setname_np(PRIVATE->thread, (const char *)tn_data.data());
|
||||||
# endif
|
# endif
|
||||||
setPriority(priority_);
|
setPriority(priority_);
|
||||||
|
// }
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -928,7 +934,10 @@ void PIThread::_endThread() {
|
|||||||
PIScopeExitCall ec([this] {
|
PIScopeExitCall ec([this] {
|
||||||
terminating = running_ = false;
|
terminating = running_ = false;
|
||||||
tid_ = -1;
|
tid_ = -1;
|
||||||
|
PRIVATE->thread = 0;
|
||||||
});
|
});
|
||||||
|
while (PRIVATE->starting)
|
||||||
|
piMinSleep();
|
||||||
// PICout(PICoutManipulators::DefaultControls) << "thread" << this << "stop" << "...";
|
// PICout(PICoutManipulators::DefaultControls) << "thread" << this << "stop" << "...";
|
||||||
stopped();
|
stopped();
|
||||||
// PICout(PICoutManipulators::DefaultControls) << "thread" << this << "stop" << "ok";
|
// PICout(PICoutManipulators::DefaultControls) << "thread" << this << "stop" << "ok";
|
||||||
|
|||||||
Reference in New Issue
Block a user