Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b1210920 authored by Keith Mok's avatar Keith Mok
Browse files

broadcast-hal: Fix mThread race condition

Currently mThread is started in initializer list, but
not in constructor, when the thread starts in initializer
list, not all class members are init yet (depends on the
order of class member declarations).
And mThread will use class members.

Putting mThread to starts in constructor ensures all
class member variables  are init before thread starts.

Bug: 231737939
Test: build
Change-Id: I4033efa9f13c2ece95c4b4f99f8c88b6d4816be1
parent 78672d1c
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -31,7 +31,11 @@ bool operator<(const WorkerThread::Task& lhs, const WorkerThread::Task& rhs) {
    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() {
    {