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 31,563 of 33,346    |
|    Marc to Alexander Terekhov    |
|    Re: atomic counter    |
|    13 Oct 11 14:09:33    |
      From: marc.glisse@gmail.com              Alexander Terekhov wrote:       > Marc wrote:       >> I am trying to make our reference counting implementation thread-safe       >> (for a very basic definition of thread-safe), which essentially means       >       > if (c.atomic_fetch_sub(1, memory_order_relaxed) == 1)       > atomic_thread_fence(memory_order_acquire),       > cleanup();       > else       > atomic_thread_fence(memory_order_release);              (trying to understand the code, not saying there is anything wrong       with it)              The standard warns that "Fences cannot, in general, be used to restore       sequential consistency for atomic operations with weaker ordering       specifications."       Good thing this is not the case here :-)              The release and acquire look like they are there so that cleanup() is       up-to-date on what other copies (sharing the same data) did to the       data (although when there are several copies, noone is supposed to       touch the data). Or maybe to make sure that cleanup happens at the       right time? And should there be something (an acquire? nothing?) on       the increment?              I'd be very grateful if you could explain the rational for the use of       acquire and release fences in your code above. It looks like you put       just the minimal synchronization in just the right places, so it would       certainly help me a lot to understand this example.              Sometimes I envy people who program in a language with a garbage       collector: no need for a counter, hence no need for atomics here...                     --        [ 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