Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3074)

Unified Diff: base/threading/thread.cc

Issue 2303943003: Ensure that |Thread::id_| is only accessed when an happens-after relationship has been established … (Closed)
Patch Set: Only AssertWaitAllowed() in WaitableEvent::TimedWait if time is non-zero Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/threading/thread.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/threading/thread.cc
diff --git a/base/threading/thread.cc b/base/threading/thread.cc
index 387c79459c196c6ac60a9678e5d464e4c71bb480..6181ba66918304d713d79dcbc3e0970276e9ea07 100644
--- a/base/threading/thread.cc
+++ b/base/threading/thread.cc
@@ -223,6 +223,7 @@ bool Thread::IsRunning() const {
void Thread::Run(RunLoop* run_loop) {
// Overridable protected method to be called from our |thread_| only.
+ DCHECK(id_event_.IsSignaled());
DCHECK_EQ(id_, PlatformThread::CurrentId());
run_loop->Run();
@@ -263,6 +264,11 @@ void Thread::SetMessageLoop(MessageLoop* message_loop) {
void Thread::ThreadMain() {
// First, make GetThreadId() available to avoid deadlocks. It could be called
// any place in the following thread initialization code.
+ DCHECK(!id_event_.IsSignaled());
+ // Note: this read of |id_| while |id_event_| isn't signaled is exceptionally
+ // okay because ThreadMain has an happens-after relationship with the other
+ // write in StartWithOptions().
+ DCHECK_EQ(kInvalidThreadId, id_);
id_ = PlatformThread::CurrentId();
DCHECK_NE(kInvalidThreadId, id_);
id_event_.Signal();
« no previous file with comments | « base/threading/thread.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698