home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.arch      Apparently more than just beeps & boops      131,241 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 130,431 of 131,241   
   David Brown to MitchAlsup   
   Re: Memory ordering (Re: Multi-precision   
   05 Dec 25 11:10:22   
   
   From: david.brown@hesbynett.no   
      
   On 04/12/2025 19:37, MitchAlsup wrote:   
   >   
   > kegs@provalid.com (Kent Dickey) posted:   
   >   
      
   > Thread-safe, by definition, is (IS) harder.   
   >   
   >> language purists still love to sneer at volatile in C-like languages as   
   >> "providing no guarantees, and so is essentially useless"--when volatile   
   >> providing no guarantees is a language and compiler choice, not something   
   >> written in stone.   
   >   
   > The problem with volatile is that all it means is the every time a volatile   
   > variable is touched, the code has to have a corresponding LD or ST. The HW   
   > ends up knowing nothing about the value's volativity and ends up in no   
   > position to help.   
   >   
      
   "volatile" /does/ provide guarantees - it just doesn't provide enough   
   guarantees for multi-threaded coding on multi-core systems.  Basically,   
   it only works at the C abstract machine level - it does nothing that   
   affects the hardware.  So volatile writes are ordered at the C level,   
   but that says nothing about how they might progress through storage   
   queues, caches, inter-processor communication buses, or whatever.  But   
   you need volatile semantics for atomics and fences as well - there's no   
   point in enforcing an order at the hardware level if the accesses can be   
   re-ordered at the software level!   
      
   "volatile" on its own is therefore not sufficient for atomics on big   
   modern processors.  But it /is/ sufficient for some uses, such as   
   accessing hardware registers, or for small atomic loads and stores on   
   single processor systems (which are far and away the biggest market, as   
   embedded microcontrollers).   
      
   As I see it, the biggest problem with "volatile" in C is   
   misunderstandings and misuse of all sorts.  At least, that's what I see   
   in my field of embedded development.   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca