Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I have just found this question because I was asking myself the same thing. According to <a href="https://blogs.oracle.com/dave/entry/a_race_in_locksupport_park" rel="nofollow">this article</a> by Oracle researcher <a href="https://labs.oracle.com/pls/apex/f?p=labs%3abio:0:29" rel="nofollow">David Dice</a>, the answer seems to be <strong>no</strong>. Here's the relevant part of the article:</p> <blockquote> <p>If a thread is blocked in <code>park()</code> we're guaranteed that a subsequent <code>unpark()</code> will make it ready. A perfectly legal but low-quality implementation of <code>park()</code> and <code>unpark()</code> would be empty methods, in which the program degenerates to simple spinning. <strong>An in fact that's the litmus test for correct <code>park()</code>-<code>unpark()</code> usage.</strong></p> </blockquote> <p>Empty <code>park()</code> and <code>unpark()</code> methods do not give you any <em>happens-before</em> relationship guarantees, so for your program to be 100% portable, you should not rely on them.</p> <p>Then again, the <a href="http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/locks/LockSupport.html" rel="nofollow">Javadoc of LockSupport</a> says:</p> <blockquote> <p>These methods are designed to be used as tools for creating higher-level synchronization utilities, and are not in themselves useful for most concurrency control applications. The <code>park</code> method is designed for use only in constructions of the form:</p> <p><code>while (!canProceed()) { ... LockSupport.park(this); }</code></p> </blockquote> <p>Since you have to explicitly check some condition anyway, which will either involve <code>volatile</code> or properly synchronized variables, the weak guarantees of <code>park()</code> should not actually be problem, right?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload