Reviewers: Jakob,

Description:
Avoid data race in debug mode on the parallel thread.

[email protected]
BUG=

Please review this at https://codereview.chromium.org/18194004/

SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge

Affected files:
  M src/optimizing-compiler-thread.h
  M src/optimizing-compiler-thread.cc


Index: src/optimizing-compiler-thread.cc
diff --git a/src/optimizing-compiler-thread.cc b/src/optimizing-compiler-thread.cc index b9ff7d83eca369c0b194ab2cd40ccdec5c9379be..a38a0db9b08bc96ecca9fc6d0a3272e6e6a8648e 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,7 +158,8 @@ void OptimizingCompilerThread::QueueForOptimization(
 #ifdef DEBUG
 bool OptimizingCompilerThread::IsOptimizerThread() {
   if (!FLAG_parallel_recompilation) return false;
-  return ThreadId::Current().ToInteger() == thread_id_;
+  ScopedLock lock(thread_id_mutex_);
+  return  ThreadId::Current().ToInteger() == thread_id_;
 }
 #endif

Index: src/optimizing-compiler-thread.h
diff --git a/src/optimizing-compiler-thread.h b/src/optimizing-compiler-thread.h index 004fce7adac9253c5088dab83e13d46b0d3e2b60..59c94cb214263a365d181e3c47407502f21fc838 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_;


--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to