From 41cac47d570a4667fac13de15965f476dcdcb8c9 Mon Sep 17 00:00:00 2001 From: "yangguo@chromium.org" Date: Fri, 28 Jun 2013 11:24:27 +0000 Subject: [PATCH] Avoid data race in debug mode on the parallel thread. R=jkummerow@chromium.org BUG= Review URL: https://codereview.chromium.org/18194004 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@15376 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/optimizing-compiler-thread.cc | 5 ++++- src/optimizing-compiler-thread.h | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/optimizing-compiler-thread.cc b/src/optimizing-compiler-thread.cc index b9ff7d8..dbf9ad7 100644 --- a/src/optimizing-compiler-thread.cc +++ b/src/optimizing-compiler-thread.cc @@ -39,7 +39,9 @@ namespace internal { void OptimizingCompilerThread::Run() { #ifdef DEBUG - thread_id_ = ThreadId::Current().ToInteger(); + { ScopedLock lock(thread_id_mutex_); + thread_id_ = ThreadId::Current().ToInteger(); + } #endif Isolate::SetIsolateThreadLocals(isolate_, NULL); DisallowHeapAllocation no_allocation; @@ -156,6 +158,7 @@ void OptimizingCompilerThread::QueueForOptimization( #ifdef DEBUG bool OptimizingCompilerThread::IsOptimizerThread() { if (!FLAG_parallel_recompilation) return false; + ScopedLock lock(thread_id_mutex_); return ThreadId::Current().ToInteger() == thread_id_; } #endif diff --git a/src/optimizing-compiler-thread.h b/src/optimizing-compiler-thread.h index 004fce7..59c94cb 100644 --- a/src/optimizing-compiler-thread.h +++ b/src/optimizing-compiler-thread.h @@ -46,6 +46,7 @@ class OptimizingCompilerThread : public Thread { Thread("OptimizingCompilerThread"), #ifdef DEBUG thread_id_(0), + thread_id_mutex_(OS::CreateMutex()), #endif isolate_(isolate), stop_semaphore_(OS::CreateSemaphore(0)), @@ -89,6 +90,7 @@ class OptimizingCompilerThread : public Thread { private: #ifdef DEBUG int thread_id_; + Mutex* thread_id_mutex_; #endif Isolate* isolate_; -- 2.7.4