Advertisement
Guest User

Untitled

a guest
Jan 30th, 2017
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.73 KB | None | 0 0
  1.   public void run() {
  2.         if (state != NEW ||
  3.             !UNSAFE.compareAndSwapObject(this, runnerOffset,
  4.                                          null, Thread.currentThread()))
  5.             return;
  6.         try {
  7.             Callable<V> c = callable;
  8.             if (c != null && state == NEW) {
  9.                 V result;
  10.                 boolean ran;
  11.                 try {
  12.                     result = c.call();
  13.                     ran = true;
  14.                 } catch (Throwable ex) {
  15.                     result = null;
  16.                     ran = false;
  17.                     setException(ex);
  18.                 }
  19.                 if (ran)
  20.                     set(result);
  21.             }
  22.         } finally {
  23.             // runner must be non-null until state is settled to
  24.             // prevent concurrent calls to run()
  25.             runner = null;
  26.             // state must be re-read after nulling runner to prevent
  27.             // leaked interrupts
  28.             int s = state;
  29.             if (s >= INTERRUPTING)
  30.                 handlePossibleCancellationInterrupt(s);
  31.         }
  32.     }
  33.  
  34.  
  35.  
  36. /**
  37.      * Causes this future to report an {@link ExecutionException}
  38.      * with the given throwable as its cause, unless this future has
  39.      * already been set or has been cancelled.
  40.      *
  41.      * <p>This method is invoked internally by the {@link #run} method
  42.      * upon failure of the computation.
  43.      *
  44.      * @param t the cause of failure
  45.      */
  46.     protected void setException(Throwable t) {
  47.         if (UNSAFE.compareAndSwapInt(this, stateOffset, NEW, COMPLETING)) {
  48.             outcome = t;
  49.             UNSAFE.putOrderedInt(this, stateOffset, EXCEPTIONAL); // final state
  50.             finishCompletion();
  51.         }
  52.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement