TaskQueueStdlib: initialize the thread last. TaskQueueStdlib initialized it's thread too early which permitted it to access uninitialized attributes. Also remove the |stopped_| event which isn't needed because of the platform thread being joinable. Fixed: webrtc:12876 Change-Id: Ibd27ce915e0e3ac92ebafca535c5a3fd72f9165e Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/223340 Commit-Queue: Markus Handell <handellm@webrtc.org> Reviewed-by: Harald Alvestrand <hta@webrtc.org> Cr-Commit-Position: refs/heads/master@{#34355}
diff --git a/rtc_base/task_queue_stdlib.cc b/rtc_base/task_queue_stdlib.cc index 548f7ef..41da285 100644 --- a/rtc_base/task_queue_stdlib.cc +++ b/rtc_base/task_queue_stdlib.cc
@@ -82,16 +82,9 @@ // Indicates if the thread has started. rtc::Event started_; - // Indicates if the thread has stopped. - rtc::Event stopped_; - // Signaled whenever a new task is pending. rtc::Event flag_notify_; - // Contains the active worker thread assigned to processing - // tasks (including delayed tasks). - rtc::PlatformThread thread_; - Mutex pending_lock_; // Indicates if the worker thread needs to shutdown now. @@ -114,12 +107,17 @@ // std::unique_ptr out of the queue without the presence of a hack. std::map<DelayedEntryTimeout, std::unique_ptr<QueuedTask>> delayed_queue_ RTC_GUARDED_BY(pending_lock_); + + // Contains the active worker thread assigned to processing + // tasks (including delayed tasks). + // Placing this last ensures the thread doesn't touch uninitialized attributes + // throughout it's lifetime. + rtc::PlatformThread thread_; }; TaskQueueStdlib::TaskQueueStdlib(absl::string_view queue_name, rtc::ThreadPriority priority) : started_(/*manual_reset=*/false, /*initially_signaled=*/false), - stopped_(/*manual_reset=*/false, /*initially_signaled=*/false), flag_notify_(/*manual_reset=*/false, /*initially_signaled=*/false), thread_(rtc::PlatformThread::SpawnJoinable( [this] { @@ -141,8 +139,6 @@ NotifyWake(); - stopped_.Wait(rtc::Event::kForever); - thread_.Finalize(); delete this; } @@ -243,8 +239,6 @@ else flag_notify_.Wait(task.sleep_time_ms_); } - - stopped_.Set(); } void TaskQueueStdlib::NotifyWake() {