Bug 757375: concurrency documentation updates (p=proberts)
authorDan Schaffer <Dan.Schaffer@adobe.com>
Fri, 21 Sep 2012 08:22:48 -0700
changeset 7552 3fc566f3a8b38589fc4b82117259bd10a9d5337f
parent 7551 cbbd13ae92cc51cfe1213e828b1d5889b187c298
child 7553 92308b4ab38931aad16c6899c86886e680943e42
push id4259
push userdschaffe@adobe.com
push dateFri, 21 Sep 2012 15:36:33 +0000
bugs757375, 1116130
Bug 757375: concurrency documentation updates (p=proberts) CL@1116130
core/concurrent.as
--- a/core/concurrent.as
+++ b/core/concurrent.as
@@ -16,22 +16,22 @@ include "api-versions.as"
  * shared resource at a time. The primary use for a Mutex is to manage code in 
  * different workers accessing a shareable byte array (a ByteArray object whose 
  * <code>shareable</code> property is <code>true</code>). However, a Mutex can be 
  * used to manage workers' access to any shareable resource, such as an AIR native 
  * extension or a filesystem file. No matter what the resource, the purpose of 
  * the mutex is to ensure that only one set of code accesses the resource at a time.
  *
  * <p>A mutex manages access using the concept of resource ownership. At any 
- time a single mutex is "owned" by at most one worker. When ownership of a 
- mutex switches from one worker to another the transision is atomic. This 
- guarantees that it will never be possible for more than one worker to take 
- ownership of the mutex. As long as code in a worker only operates on a shared 
- resource when that worker owns the mutex, you can be certain that there will 
- never be a conflict from multiple workers.</p>
+ * time a single mutex is "owned" by at most one worker. When ownership of a 
+ * mutex switches from one worker to another the transision is atomic. This 
+ * guarantees that it will never be possible for more than one worker to take 
+ * ownership of the mutex. As long as code in a worker only operates on a shared 
+ * resource when that worker owns the mutex, you can be certain that there will 
+ * never be a conflict from multiple workers.</p>
  * 
  * <p>Use the <code>tryLock()</code> method to take ownership of the mutex if 
  * it is available. Use the <code>lock()</code> method to pause the current 
  * worker's execution until the mutex is available, then take ownership of the 
  * mutex. Once the current worker has ownership of the mutex, it can safely 
  * operate on the shared resource. When those operations are complete, call the 
  * <code>unlock()</code> method to release the mutex. At that point the current 
  * worker should no longer access the shared resource.</p>
@@ -42,125 +42,124 @@ include "api-versions.as"
  * <code>setSharedProperty()</code> method or by using a MessageChannel object, 
  * both workers have a reference to the same Mutex object in the runtime's memory.</p>
  *
  * @see flash.system.Worker Worker class
  * @see flash.utils.ByteArray#shareable ByteArray.shareable property
  * @see flash.concurrent.Condition Condition class
  *
  * @langversion 3.0
- * @playerversion Flash 11.4	
- * @playerversion AIR 3.4
+ * @playerversion Flash 11.5	
+ * @playerversion AIR 3.5
  */
 [API(CONFIG::SWF_18)]
 [native(cls="MutexClass",instance="MutexObject",gc="exact")]
 final public class Mutex
 {
     /**
      * Creates a new Mutex instance.
      *
      * @throws Error if the mutex could not be initialized.
+     * 
      * @langversion 3.0
-     * @playerversion Flash 11.4	
-     * @playerversion AIR 3.4
+     * @playerversion Flash 11.5	
+     * @playerversion AIR 3.5
      */
     public function Mutex()
     {
         ctor();
     }
 
     /**
      * Pauses execution of the current worker until this mutex is available and 
-     * then takes ownership of the mutex. If another worker currently owns the 
-     * mutex, the calling worker's execution thread pauses at the 
+     * then takes ownership of the mutex. If another worker owns the 
+     * mutex when <code>lock()</code> is called, the calling worker's execution thread pauses at the 
      * <code>lock()</code> call and the worker is added to the queue of ownership 
-     * requests. Once it is this worker's turn to own the mutex, the worker's 
+     * requests. Once the calling worker acquires the mutex, the worker's 
      * execution continues with the line of code following the 
      * <code>lock()</code> call.
      *
      * <p>Once the current worker has ownership of the mutex, it can safely 
      * operate on the shared resource. When those operations are complete, call 
      * the <code>unlock()</code> method to release the mutex. At that point the 
      * current worker should no longer access the shared resource.</p>
      *
      * <p>Internally, a mutex keeps a count of the number of lock requests it 
      * has received. The mutex must receive the same number of unlock requests 
      * before it is completely released. If code in the worker that owns the 
      * mutex locks it again (by calling the <code>lock()</code> method) the 
      * internal lock count increases by one. You must call the 
      * <code>unlock()</code> method as many times as the number of lock requests 
      * to release ownership of the mutex.</p>
      * 
-     * <p>Under contention, locks favor granting access to the longest-waiting worker
-     * and guarantee lack of starvation. Otherwise there is no guarantee in any 
-     * particular access order. Note however, that fairness of lock ordering does 
-     * not guarantee fairness of worker scheduling. </p>
+     * <p>When multiple workers are waiting for a mutex, the mutex gives priority
+     * to assigning ownership to the longest-waiting worker. However, scheduling 
+     * of worker threads is managed by the host operating system so there is no 
+     * guarantee of a particular code execution order across workers.</p>
      *
      * @langversion 3.0
-     * @playerversion Flash 11.4	
-     * @playerversion AIR 3.4
+     * @playerversion Flash 11.5	
+     * @playerversion AIR 3.5
      */
     public native function lock() :void
 
     /**
-     * Acquires ownership of the mutex if it is available. Otherwise, calling 
-     * this method returns <code>false</code> and code execution continues 
-     * immediately.
+     * Acquires ownership of the mutex if it is available. If another worker 
+     * already owns the mutex or another worker has called the <code>lock()</code> 
+     * method and is waiting to acquire the mutex, the mutex is not available. 
+     * In that case, calling this method returns <code>false</code> and code 
+     * execution continues immediately.
      *
      * <p>Once the current worker has ownership of the mutex, it can safely 
      * operate on the shared resource. When those operations are complete, call 
      * the <code>unlock()</code> method to release the mutex. At that point the 
      * current worker should no longer access the shared resource.</p>
      *
-     * <p>Under contention, locks favor granting access to the longest-waiting worker
-     * and guarantee lack of starvation. Otherwise there is no guarantee in any 
-     * particular access order. Note however, that fairness of lock ordering does 
-     * not guarantee fairness of worker scheduling. </p>
-     *
-     * <p>This method will never return <code>true</code>
-     * while there are workers already waiting on the lock, even if the lock is
-     * available at the time of the call.</p>
+     * <p>When multiple workers are waiting for a mutex, the mutex gives priority
+     * to assigning ownership to the longest-waiting worker. However, scheduling 
+     * of worker threads is managed by the host operating system so there is no 
+     * guarantee of a particular code execution order across workers.</p>
      *
      * @return <code>true</code> if the mutex was available (and is now owned 
      * by the current worker), or <code>false</code> if the current worker did 
-     * not acquire ownership of the mutex or there are workers waiting on acquisition
-     * of this mutex.
+     * not acquire ownership of the mutex.
      *
      * @langversion 3.0
-     * @playerversion Flash 11.4	
-     * @playerversion AIR 3.4
+     * @playerversion Flash 11.5	
+     * @playerversion AIR 3.5
      */
     public native function tryLock() :Boolean;
 
     /**
      * Releases ownership of this mutex, allowing any worker to acquire it and 
      * perform work on the associated resource.
      *
      * <p>Internally, a mutex keeps a count of the number of lock requests it 
      * has received. Code in a worker must call the <code>unlock()</code> 
      * method as many times as the number of lock requests in order to release 
      * ownership of the mutex.</p>
      * 
      * @throws flash.errors.IllegalOperationError when the current worker 
      *         doesn't own the mutex.
      *
      * @langversion 3.0
-     * @playerversion Flash 11.4	
-     * @playerversion AIR 3.4
+     * @playerversion Flash 11.5	
+     * @playerversion AIR 3.5
      */
     native public function unlock():void;
     
     /**
-     * Indicates if a <code>Mutex</code> is supported for the current platform.
+     * Indicates whether the use of the Mutex class is supported for the current platform.
      *
-	 * <p>If the current platform supports <code>Mutex</code>, this property's value is <code>true</code>.
-	 *
+     * <p>This property is <code>true</code> if the current platform supports mutexes; otherwise
+     * <code>false</code>.</p>
+     *
      * @langversion 3.0
-     * @playerversion Flash 11.4	
-     * @playerversion AIR 3.4
+     * @playerversion Flash 11.5	
+     * @playerversion AIR 3.5
      */
     public native static function get isSupported(): Boolean;
 
     private native function ctor() :void;
 }
     
 /**
  * A Condition object is a tool for sharing a resource between workers with the 
@@ -208,44 +207,44 @@ final public class Mutex
  * <code>setSharedProperty()</code> method or by using a MessageChannel object, 
  * both workers have a reference to the same Condition object in the runtime's 
  * memory.</p>
  *
  * @see flash.concurrent.Mutex Mutex class
  * @see flash.system.Worker Worker class
  * 
  * @langversion 3.0
- * @playerversion Flash 11.4	
- * @playerversion AIR 3.4
+ * @playerversion Flash 11.5	
+ * @playerversion AIR 3.5
  */
 [API(CONFIG::SWF_18)]
 [native(cls="ConditionClass",instance="ConditionObject",gc="exact")]
 final public class Condition 
 {
     /**
      * Creates a new Condition instance.
      *
      * @param mutex the mutex that the condition uses to control transitions 
     *               between workers
      *
      * @langversion 3.0
-     * @playerversion Flash 11.4	
-     * @playerversion AIR 3.4
+     * @playerversion Flash 11.5	
+     * @playerversion AIR 3.5
      */
     public function Condition(mutex:Mutex)
     {
         ctor(mutex);
     }
 
     /**
      * The mutex associated with this condition.
      *
      * @langversion 3.0
-     * @playerversion Flash 11.4	
-     * @playerversion AIR 3.4
+     * @playerversion Flash 11.5	
+     * @playerversion AIR 3.5
      */
      public native function get mutex():Mutex;
 
 
     /**
      * Specifies that the condition that this Condition object represents isn't 
      * satisfied, and the current worker needs to wait until it is satisfied 
      * before executing more code. Calling this method pauses the current 
@@ -267,23 +266,22 @@ final public class Condition
      *
      * @throws ArgumentError if the <code>timeout</code> argument is less than 
      *         0 and not -1
      * 
      * @throws flash.errors.ScriptTimeoutError if the method is called from 
      *         code in the primordial worker in Flash Player and worker pauses 
      *         longer than the script timeout limit (15 seconds by default)
      *
-     * @throws flash.errors.WorkerTerminatedError if the method is called and
-     *         the associated worker is terminated while the calling worker
-     *         is waiting.
+     * @throws flash.errors.Error if the method is called and, while the calling 
+     *         worker's execution is paused, the waiting worker is terminated.
      *
      * @langversion 3.0
-     * @playerversion Flash 11.4	
-     * @playerversion AIR 3.4
+     * @playerversion Flash 11.5	
+     * @playerversion AIR 3.5
      */
     public native function wait(timeout:Number = -1) :Boolean;
 
     /**
      * Specifes that the condition that this Condition object represents has 
      been satisfied and that ownership of the mutex will be returned to the 
      next worker (if any) that's waiting on this condition.
      *
@@ -297,18 +295,18 @@ final public class Condition
      * <p>One the mutex's lock is released, the next worker in the queue of 
      * workers that have called the <code>wait()</code> method acquires the 
      * mutex and resumes code execution.</p>
      *
      * @throws flash.errors.IllegalOperationError if the current worker doesn't 
      *         own this condition's mutex
      *
      * @langversion 3.0
-     * @playerversion Flash 11.4	
-     * @playerversion AIR 3.4
+     * @playerversion Flash 11.5	
+     * @playerversion AIR 3.5
      */
     public native function notify() :void;
 
     /**
      * Specifies that the condition that this Condition object represents has 
      * been satisfied and that ownership of the mutex will be returned to all 
      * workers that are waiting on this condition.
      * 
@@ -327,56 +325,57 @@ final public class Condition
      * method, mutex ownership then switches to the next waiting worker. Each 
      * time mutex ownership switches between workers, the transition is performed 
      * as a single atomic operation.</p>
      *
      * @throws flash.errors.IllegalOperationError if the current worker doesn't 
      *         own this condition's mutex
      *
      * @langversion 3.0
-     * @playerversion Flash 11.4	
-     * @playerversion AIR 3.4
+     * @playerversion Flash 11.5	
+     * @playerversion AIR 3.5
      */
     public native function notifyAll() :void;
 
     /**
-     * Indicates if a <code>Condition</code> is supported for the current platform.
-     * NOTE: if <code>Mutex</code> is not supported creation of a <code>Condition</code>
-     * is not possible.
+     * Indicates whether the Condition class is supported for the current platform.
      *
-	 * <p>If the current platform supports <code>Condition</code>, this property's value is <code>true</code>.
+     * <p><strong>Note</strong>: if the Mutex class is not supported, creation 
+     * of a Condition instance is not possible and this property is <code>false</code>.</p>
      *
      * @langversion 3.0
-     * @playerversion Flash 11.4	
-     * @playerversion AIR 3.4
+     * @playerversion Flash 11.5	
+     * @playerversion AIR 3.5
      */
     public native static function get isSupported(): Boolean;
     
     private native function ctor(mutex:Mutex) :void;
 }
 
 }
 
 package avm2.intrinsics.memory
 {
     /**
+     * @private
      * A complete memory barrier for domainMemory (for both load and store instructions).
      *
      * @langversion 3.0
-     * @playerversion Flash 11.4	
-     * @playerversion AIR 3.4
+     * @playerversion Flash 11.5	
+     * @playerversion AIR 3.5
      */
 	[API(CONFIG::SWF_18)]
 	[native("ConcurrentMemory::mfence")]
 	public native function mfence():void;
     /**
+     * @private
      * A compare and swap for domainMemory.
      * Behaves like ByteArray.atomicCompareAndSwapIntAt but operates on the current domainMemory.
      *
      * @langversion 3.0
-     * @playerversion Flash 11.4	
-     * @playerversion AIR 3.4
+     * @playerversion Flash 11.5	
+     * @playerversion AIR 3.5
      */
 	[API(CONFIG::SWF_18)]
 	[native("ConcurrentMemory::casi32")]
 	public native function casi32(addr:int, expectedVal:int, newVal:int):int;
 }