Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You're correct that you do not need a special instruction to atomically read a 32bit integer, however, what that means is you will get the "whole" value (i.e. you won't get <em>part of one write and part of another</em>). You have no guarantees that the value won't have changed once you have read it.</p> <p>It is at this point where you need to decide if you need to use some other synchronization method to control access, say if you're using this value to read a member from an array, etc.</p> <hr> <p>In a nutshell, <strong>atomicity</strong> ensures an operation happens completely and indivisibly. Given some operation <code>A</code> that contained <code>N</code> steps, if you made it to the operation right after <code>A</code> you can be assured that all <code>N</code> steps happened in isolation from concurrent operations.</p> <p>If you had two threads which executed the atomic operation <code>A</code> you are guaranteed you will see only the <strong>complete</strong> result of <em>one of the two</em> threads. If you want to coordinate the threads, atomic operations could be used to create the required synchronization. But atomic operations in and of themselves do not provide higher level synchronization. The <code>Interlocked</code> family of methods are made available to provide some fundamental atomic operations.</p> <p><strong>Synchronization</strong> is a broader kind of concurrency control, often built around <em>atomic</em> operations. Most processors include memory barriers which allow you to ensure all cache lines are flushed and you have a <strong>consistent</strong> view of memory. Volatile reads are a way to ensure consistent access to a given memory location.</p> <p>While not immediately applicable to your problem, reading up on ACID (atomicity, consistency, isolation, and durability) with respect to databases may help you with the terminology.</p>
 

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