예제 #1
0
 public virtual bool Cancel(bool mayInterruptIfRunning)
 {
     if (!(State == NEW && UNSAFE.compareAndSwapInt(this, StateOffset, NEW, mayInterruptIfRunning ? INTERRUPTING : CANCELLED)))
     {
         return(false);
     }
     try             // in case call to interrupt throws exception
     {
         if (mayInterruptIfRunning)
         {
             try
             {
                 Thread t = Runner;
                 if (t != null)
                 {
                     t.Interrupt();
                 }
             }                     // final state
             finally
             {
                 UNSAFE.putOrderedInt(this, StateOffset, INTERRUPTED);
             }
         }
     }
     finally
     {
         FinishCompletion();
     }
     return(true);
 }
예제 #2
0
 /// <summary>
 /// Sets the result of this future to the given value unless
 /// this future has already been set or has been cancelled.
 ///
 /// <para>This method is invoked internally by the <seealso cref="#run"/> method
 /// upon successful completion of the computation.
 ///
 /// </para>
 /// </summary>
 /// <param name="v"> the value </param>
 protected internal virtual void Set(V v)
 {
     if (UNSAFE.compareAndSwapInt(this, StateOffset, NEW, COMPLETING))
     {
         Outcome = v;
         UNSAFE.putOrderedInt(this, StateOffset, NORMAL);                 // final state
         FinishCompletion();
     }
 }
예제 #3
0
 /// <summary>
 /// CASes the cellsBusy field from 0 to 1 to acquire lock.
 /// </summary>
 internal bool CasCellsBusy()
 {
     return(UNSAFE.compareAndSwapInt(this, CELLSBUSY, 0, 1));
 }