Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    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. 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.
    1. COThis is interesting. I have read many articles explaining why volatile is a multi-threaded program's best friend, and many explaining why volatile has nothing to do with this and making everything volatile will simply slow the program down. In my application, more than half of the data could be accessed by any thread and any time. Should they really all be volatile? Or is this the exception because it's in a tight loop that the compiler might optimize to only check the lock once?
      singulars
    2. COi.e. Picture a function (which isn't inlined) is called, checks a variable, then returns, and is called quickly again. In this case, would volatile not be necessary because the compiler would not be able to optimize code across multiple calls? But in the loop above it might realize that lock could never change and optimize it out? So volatile has nothing to do with caching, it simply tells the compiler not to optimize access to the memory? I think this just made sense to me. Please confirm or clarify! :)
      singulars
    3. COI spent some time looking up how volatile works... In a nutshell, what it does is to prevent optimizing memory accesses, and also prevent re-ordering of memory operations involving volatile variables. (Memory operations involving non-volatile-qualified variables may be re-ordered around those involving volatile. Further, even if the writes occur in order, a different CPU may notice the new values in a different order.) This should be enough for multi-threaded synchronization _in this case_, because you also have the `__sync` routines providing a memory barrier.
      singulars
 

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