< prev index next >

src/java.base/share/classes/java/util/concurrent/locks/LockSupport.java

Print this page




 116  *       if (Thread.interrupted())
 117  *         wasInterrupted = true;
 118  *     }
 119  *
 120  *     waiters.remove();
 121  *     // ensure correct interrupt status on return
 122  *     if (wasInterrupted)
 123  *       Thread.currentThread().interrupt();
 124  *   }
 125  *
 126  *   public void unlock() {
 127  *     locked.set(false);
 128  *     LockSupport.unpark(waiters.peek());
 129  *   }
 130  *
 131  *   static {
 132  *     // Reduce the risk of "lost unpark" due to classloading
 133  *     Class<?> ensureLoaded = LockSupport.class;
 134  *   }
 135  * }}</pre>


 136  */
 137 public class LockSupport {
 138     private LockSupport() {} // Cannot be instantiated.
 139 
 140     private static void setBlocker(Thread t, Object arg) {
 141         // Even though volatile, hotspot doesn't need a write barrier here.
 142         U.putObject(t, PARKBLOCKER, arg);
 143     }
 144 
 145     /**
 146      * Makes available the permit for the given thread, if it
 147      * was not already available.  If the thread was blocked on
 148      * {@code park} then it will unblock.  Otherwise, its next call
 149      * to {@code park} is guaranteed not to block. This operation
 150      * is not guaranteed to have any effect at all if the given
 151      * thread has not been started.
 152      *
 153      * @param thread the thread to unpark, or {@code null}, in which case
 154      *        this operation has no effect
 155      */




 116  *       if (Thread.interrupted())
 117  *         wasInterrupted = true;
 118  *     }
 119  *
 120  *     waiters.remove();
 121  *     // ensure correct interrupt status on return
 122  *     if (wasInterrupted)
 123  *       Thread.currentThread().interrupt();
 124  *   }
 125  *
 126  *   public void unlock() {
 127  *     locked.set(false);
 128  *     LockSupport.unpark(waiters.peek());
 129  *   }
 130  *
 131  *   static {
 132  *     // Reduce the risk of "lost unpark" due to classloading
 133  *     Class<?> ensureLoaded = LockSupport.class;
 134  *   }
 135  * }}</pre>
 136  *
 137  * @since 1.5
 138  */
 139 public class LockSupport {
 140     private LockSupport() {} // Cannot be instantiated.
 141 
 142     private static void setBlocker(Thread t, Object arg) {
 143         // Even though volatile, hotspot doesn't need a write barrier here.
 144         U.putObject(t, PARKBLOCKER, arg);
 145     }
 146 
 147     /**
 148      * Makes available the permit for the given thread, if it
 149      * was not already available.  If the thread was blocked on
 150      * {@code park} then it will unblock.  Otherwise, its next call
 151      * to {@code park} is guaranteed not to block. This operation
 152      * is not guaranteed to have any effect at all if the given
 153      * thread has not been started.
 154      *
 155      * @param thread the thread to unpark, or {@code null}, in which case
 156      *        this operation has no effect
 157      */


< prev index next >