Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In C, the <code>volatile</code> keyword has no defined semantics that apply when a variable is accessed concurrently in multiple threads (and pthreads doesn't add any). So the only way to know if it's safe or not is to look at the effects <code>volatile</code> has on particular platforms and compilers, figure out every possible way it could go wrong on those specific hardware platforms, and rule them out.</p> <p>It's a really bad idea to do this if you have a choice. Portable code tends to be much more reliable. The two big problems are:</p> <ol> <li><p>New platforms do come out. And fragile code can break when a new CPU, compiler, or library is released.</p></li> <li><p>It's very hard to think of every way this could go wrong because you don't really know what you're working with. Mutexes, atomic operations, and the like have precisely-defined semantics for multiple threads, so you know <em>exactly</em> what guarantees you have -- on any platform, with any compiler, with any hardware.</p></li> </ol> <p>Your reader code is terrible by the way. On hyper-threaded CPUs, for example, tightly spinning like that will starve the other virtual core. Worse, you could wind up spinning at FSB speed, starving other physical cores. And when you exit the spin loop -- the time performance is most critical -- you basically force a mispredicted branch! (The exact effects depends on the specifics of the CPU, which is another reason using this kind of code is bad. You need at least a <a href="https://stackoverflow.com/a/7086289/721269">rep nop</a>.)</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.
 

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