Merge "broadcast-hal: Fix mThread race condition"
diff --git a/broadcastradio/common/utils/WorkerThread.cpp b/broadcastradio/common/utils/WorkerThread.cpp
index 31f4d3f..dd87f53 100644
--- a/broadcastradio/common/utils/WorkerThread.cpp
+++ b/broadcastradio/common/utils/WorkerThread.cpp
@@ -31,7 +31,11 @@
return lhs.when > rhs.when;
}
-WorkerThread::WorkerThread() : mIsTerminating(false), mThread(&WorkerThread::threadLoop, this) {}
+WorkerThread::WorkerThread() : mIsTerminating(false) {
+ // putting mThread in constructor instead of initializer list
+ // to ensure all class members are init before mThread starts
+ mThread = std::thread(&WorkerThread::threadLoop, this);
+}
WorkerThread::~WorkerThread() {
{