Bug 757375: Concurrency bug fixes (p=jasowill,r=dtomack)
authorDan Schaffer <Dan.Schaffer@adobe.com>
Thu, 08 Nov 2012 13:52:35 -0800
changeset 7576 d45c5d35e6c7
parent 7575 be44a24acfa5
child 7577 f9f60574f375
push id4262
push userdschaffe@adobe.com
push dateWed, 30 Jan 2013 19:01:31 +0000
reviewersdtomack
bugs757375, 1129522, 1134141
Bug 757375: Concurrency bug fixes (p=jasowill,r=dtomack) integrate 1129522 CL@1134141
core/Isolate.cpp
--- a/core/Isolate.cpp
+++ b/core/Isolate.cpp
@@ -580,16 +580,17 @@ throw_terminated_error:
     {
         return m_aggregate->isPrimordial(m_desc);
     }
      
     void Isolate::run() 
     {
         // Make sure the isolate survives for the duration of the doRun() call by keeping a ref to it.
         FixedHeapRef<Isolate> handle(this);
+		DecrementRef();		// Let go of the hand-over-hand-safety-ref set by spawnIsolateThread() now that handle is valid.
 
         // don't run if interrupted
         if (m_interrupted) {
             m_aggregate->stateTransition(this, Isolate::TERMINATED);
         }
         else {
             m_aggregate->stateTransition(this, Isolate::STARTING);
 		    doRun();
@@ -964,21 +965,27 @@ throw_terminated_error:
 		
         SCOPE_LOCK(m_globals.m_lock) {
 #ifdef _DEBUG
             vmbase::VMThread* t;
 #endif // _DEBUG
 
             AvmAssert(m_activeIsolateThreadMap.LookupItem(isolate->getDesc(), &t) == false);
             vmbase::VMThread* thread = mmfx_new(vmbase::VMThread(isolate));
+			// increment the refcount on the isolate as a hand-over-hand-safety measure to ensure that 
+			// when the thread spins up the isolate will still be around for the thread to 
+			// take a ref to the isolate.
+ 			isolate->IncrementRef();		// run() is responsible for dec ref
+
             if (thread->start()) {
                 stateTransition(isolate, Isolate::CANSTART);
 				m_activeIsolateThreadMap.InsertItem(isolate->getDesc(), thread);
 				result = true;
             } else {
+				isolate->DecrementRef();	// thread will not start, so undo the increments
                 // We will never try to spawn this isolate again.
 				stateTransition(isolate, Isolate::FAILED);
 				mmfx_delete(thread);
                 result = false;
             }
         }
         return result;
     }