home bbs files messages ]

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

   comp.lang.c++.moderated      Moderated discussion of C++ superhackery      33,346 messages   

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

   Message 32,331 of 33,346   
   Pete Becker to Rani Sharoni   
   Re: Threads: incompatibilities between C   
   24 May 12 16:28:57   
   
   13ef24ff   
   From: pete@versatilecoding.com   
      
   On 2012-05-24 09:11:58 +0000, Rani Sharoni said:   
      
   >   
   > Thanks for the explanation. I see your point. std::create-thread is a   
   > full memory barrier so for example there is no need for additional   
   > barriers in order to access (from the new thread) memory that was   
   > initialized before the create-thread call (i.e. no re-ordering is   
   > allowed by the caller).   
      
   There are two things that are enforced by barriers: no re-ordering, and   
   cache coherence. For those who aren't up on this stuff, no re-ordering   
   means the compiler can't rearrange the code in ways that invalidate the   
   read/write rules. Cache coherence means that the hardware can't   
   rearrange reads and writes. The underlying hardware issue is that,   
   typically, with multiple cpus you have multiple caches; a write by one   
   cpu writes data to its cache; a read by another cpu may read from its   
   own cache or from main memory; if the contents of the first cache   
   haven't been written to main memory, the read won't see the result of   
   that write. Memory barriers (which underly the implementation of the   
   "synchronizes with" relationship) do the appropriate flushes. A release   
   operation flushes the cpu's cache, storing newly written values to main   
   memory; an acquire operation invalidates the cpu's cache, forcing data   
   to be read from main memory instead of the cache. The combination of   
   the two produces "synchronizes with": a write operation with release   
   semantics on one cpu synchronizes with a read operation with acquire   
   semantics on another cpu if the read sees the value that was written.   
   Again, that means that writes prior to the release operation are   
   visible to readers after the acquire operation.   
      
   --   
    Pete   
   Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The   
   Standard C++ Library Extensions: a Tutorial and Reference   
   (www.petebecker.com/tr1book)   
      
      
         [ See http://www.gotw.ca/resources/clcm.htm for info about ]   
         [ comp.lang.c++.moderated.    First time posters: Do this! ]   
      
   --- 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