Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>1) lock-free operation are performed using atomic operation, now what are these atomic operation ?</p> </blockquote> <p>E.g. incrementing a counter includes</p> <ol> <li>reading the current value,</li> <li>incrementing the value in memory,</li> <li>writing back the updated value.</li> </ol> <p>Atomicity means that these all happen as one single, uniterruptible change.</p> <blockquote> <p>i mean at certain level they also need to have a lock right ?</p> </blockquote> <p>Wrong. The basic idea behind CAS is to do the first two steps above, then before the third, they check whether the value was changed in between, and fail if so. Then the change may be retried with the new value later.</p> <p>There is no classical locking involved, as each of the 3 steps in itself is atomic. The 3rd (Compare And Swap) operation is supported by modern processors, so you <em>may</em> say it involves some sort of locking at the register level (to be frank, I don't know how exactly it is implemented), but at any rate, that is not the same as what is generally meant by locking in Java.</p> <p>The benefit of CAS is improved performance due to the fact that even with the improved locking performance in current JVMs, CAS is still cheaper, especially in case of contention (i.e. when multiple threads do collide upon an operation). In this case, using locks, one or more of the threads are suspended, and a new thread is brought into context instead, which is a very costly operation even when it doesn't involve swapping memory.</p> <blockquote> <p>2) they say non-blocking list, Now what a non-blocking list should be</p> </blockquote> <p>Here you may be confusing two different terms. A non-blocking list is one which does not block on insertions/removals, which usually means its size is not bounded (e.g. <a href="http://download.oracle.com/javase/6/docs/api/java/util/concurrent/CopyOnWriteArrayList.html" rel="nofollow"><code>CopyOnWriteArrayList</code></a>). Contrast this with e.g. a <em>blocking queue</em> (e.g. <a href="http://download.oracle.com/javase/6/docs/api/java/util/concurrent/ArrayBlockingQueue.html" rel="nofollow"><code>ArrayBlockingQueue</code></a>), which has a fixed maximum size, and upon reaching its size limit, additional insert calls are <em>blocked</em> until more space is available (after some other thread removes element(s) from the queue).</p> <p>A collection which achieves thread safety using a lock-free algorithm (such as <a href="http://download.oracle.com/javase/6/docs/api/java/util/concurrent/ConcurrentHashMap.html" rel="nofollow"><code>ConcurrentHashMap</code></a>) is not the same as a non-blocking collection.</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