/// <summary> /// Disables the current thread for thread scheduling purposes, for up to /// the specified waiting time, unless the permit is available. /// /// <para>If the permit is available then it is consumed and the call /// returns immediately; otherwise the current thread becomes disabled /// for thread scheduling purposes and lies dormant until one of four /// things happens: /// /// <ul> /// <li>Some other thread invokes <seealso cref="#unpark unpark"/> with the /// current thread as the target; or /// /// <li>Some other thread <seealso cref="Thread#interrupt interrupts"/> /// the current thread; or /// /// <li>The specified waiting time elapses; or /// /// <li>The call spuriously (that is, for no reason) returns. /// </ul> /// /// </para> /// <para>This method does <em>not</em> report which of these caused the /// method to return. Callers should re-check the conditions which caused /// the thread to park in the first place. Callers may also determine, /// for example, the interrupt status of the thread, or the elapsed time /// upon return. /// /// </para> /// </summary> /// <param name="nanos"> the maximum number of nanoseconds to wait </param> public static void ParkNanos(long nanos) { if (nanos > 0) { UNSAFE.park(false, nanos); } }
/// <summary> /// Disables the current thread for thread scheduling purposes, until /// the specified deadline, unless the permit is available. /// /// <para>If the permit is available then it is consumed and the call /// returns immediately; otherwise the current thread becomes disabled /// for thread scheduling purposes and lies dormant until one of four /// things happens: /// /// <ul> /// <li>Some other thread invokes <seealso cref="#unpark unpark"/> with the /// current thread as the target; or /// /// <li>Some other thread <seealso cref="Thread#interrupt interrupts"/> the /// current thread; or /// /// <li>The specified deadline passes; or /// /// <li>The call spuriously (that is, for no reason) returns. /// </ul> /// /// </para> /// <para>This method does <em>not</em> report which of these caused the /// method to return. Callers should re-check the conditions which caused /// the thread to park in the first place. Callers may also determine, /// for example, the interrupt status of the thread, or the current time /// upon return. /// /// </para> /// </summary> /// <param name="blocker"> the synchronization object responsible for this /// thread parking </param> /// <param name="deadline"> the absolute time, in milliseconds from the Epoch, /// to wait until /// @since 1.6 </param> public static void ParkUntil(Object blocker, long deadline) { Thread t = Thread.CurrentThread; SetBlocker(t, blocker); UNSAFE.park(true, deadline); SetBlocker(t, null); }
/// <summary> /// Disables the current thread for thread scheduling purposes unless the /// permit is available. /// /// <para>If the permit is available then it is consumed and the call returns /// immediately; otherwise /// the current thread becomes disabled for thread scheduling /// purposes and lies dormant until one of three things happens: /// /// <ul> /// <li>Some other thread invokes <seealso cref="#unpark unpark"/> with the /// current thread as the target; or /// /// <li>Some other thread <seealso cref="Thread#interrupt interrupts"/> /// the current thread; or /// /// <li>The call spuriously (that is, for no reason) returns. /// </ul> /// /// </para> /// <para>This method does <em>not</em> report which of these caused the /// method to return. Callers should re-check the conditions which caused /// the thread to park in the first place. Callers may also determine, /// for example, the interrupt status of the thread upon return. /// /// </para> /// </summary> /// <param name="blocker"> the synchronization object responsible for this /// thread parking /// @since 1.6 </param> public static void Park(Object blocker) { Thread t = Thread.CurrentThread; SetBlocker(t, blocker); UNSAFE.park(false, 0L); SetBlocker(t, null); }
/// <summary> /// Disables the current thread for thread scheduling purposes, for up to /// the specified waiting time, unless the permit is available. /// /// <para>If the permit is available then it is consumed and the call /// returns immediately; otherwise the current thread becomes disabled /// for thread scheduling purposes and lies dormant until one of four /// things happens: /// /// <ul> /// <li>Some other thread invokes <seealso cref="#unpark unpark"/> with the /// current thread as the target; or /// /// <li>Some other thread <seealso cref="Thread#interrupt interrupts"/> /// the current thread; or /// /// <li>The specified waiting time elapses; or /// /// <li>The call spuriously (that is, for no reason) returns. /// </ul> /// /// </para> /// <para>This method does <em>not</em> report which of these caused the /// method to return. Callers should re-check the conditions which caused /// the thread to park in the first place. Callers may also determine, /// for example, the interrupt status of the thread, or the elapsed time /// upon return. /// /// </para> /// </summary> /// <param name="blocker"> the synchronization object responsible for this /// thread parking </param> /// <param name="nanos"> the maximum number of nanoseconds to wait /// @since 1.6 </param> public static void ParkNanos(Object blocker, long nanos) { if (nanos > 0) { Thread t = Thread.CurrentThread; SetBlocker(t, blocker); UNSAFE.park(false, nanos); SetBlocker(t, null); } }
/// <summary> /// Disables the current thread for thread scheduling purposes, until /// the specified deadline, unless the permit is available. /// /// <para>If the permit is available then it is consumed and the call /// returns immediately; otherwise the current thread becomes disabled /// for thread scheduling purposes and lies dormant until one of four /// things happens: /// /// <ul> /// <li>Some other thread invokes <seealso cref="#unpark unpark"/> with the /// current thread as the target; or /// /// <li>Some other thread <seealso cref="Thread#interrupt interrupts"/> /// the current thread; or /// /// <li>The specified deadline passes; or /// /// <li>The call spuriously (that is, for no reason) returns. /// </ul> /// /// </para> /// <para>This method does <em>not</em> report which of these caused the /// method to return. Callers should re-check the conditions which caused /// the thread to park in the first place. Callers may also determine, /// for example, the interrupt status of the thread, or the current time /// upon return. /// /// </para> /// </summary> /// <param name="deadline"> the absolute time, in milliseconds from the Epoch, /// to wait until </param> public static void ParkUntil(long deadline) { UNSAFE.park(true, deadline); }
/// <summary> /// Disables the current thread for thread scheduling purposes unless the /// permit is available. /// /// <para>If the permit is available then it is consumed and the call /// returns immediately; otherwise the current thread becomes disabled /// for thread scheduling purposes and lies dormant until one of three /// things happens: /// /// <ul> /// /// <li>Some other thread invokes <seealso cref="#unpark unpark"/> with the /// current thread as the target; or /// /// <li>Some other thread <seealso cref="Thread#interrupt interrupts"/> /// the current thread; or /// /// <li>The call spuriously (that is, for no reason) returns. /// </ul> /// /// </para> /// <para>This method does <em>not</em> report which of these caused the /// method to return. Callers should re-check the conditions which caused /// the thread to park in the first place. Callers may also determine, /// for example, the interrupt status of the thread upon return. /// </para> /// </summary> public static void Park() { UNSAFE.park(false, 0L); }