Note that there are some explanatory texts on larger screens.

plurals
  1. POMultithreaded paranoia
    primarykey
    data
    text
    <p>This is a complex question, please consider carefully before answering.</p> <p>Consider this situation. Two threads (a reader and a writer) access a single global <code>int</code>. Is this safe? Normally, I would respond without thought, yes!</p> <p>However, it seems to me that Herb Sutter doesn't think so. In his articles on effective concurrency he discusses a <a href="http://www.ddj.com/cpp/210600279" rel="nofollow noreferrer">flawed lock-free queue</a> and the <a href="http://www.ddj.com/hpc-high-performance-computing/210604448" rel="nofollow noreferrer">corrected version</a>.</p> <p>In the end of the first article and the beginning of the second he discusses a rarely considered trait of variables, write ordering. Int's are atomic, good, but ints aren't necessarily ordered which could destroy any lock-free algorithm, including my above scenario. I fully agree that the only way to <strong><em>guarantee</em></strong> correct multithreaded behavior on all platforms present and future is to use atomics(AKA memory barriers) or mutexes.</p> <p>My question; is write re-odering ever a problem on real hardware? Or is the multithreaded paranoia just being pedantic?<br> What about classic uniprocessor systems?<br> What about simpler RISC processors like an embedded power-pc?</p> <p><em>Clarification</em>: I'm more interested in what Mr. Sutter said about the hardware (processor/cache) reordering variable writes. I can stop the optimizer from breaking code with compiler switches or hand inspection of the assembly post-compilation. However, I'd like to know if the hardware can still mess up the code in practice.</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.
 

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