[cpp-threads] [Javamemorymodel-discussion] there's a happens-before orderhere. right?
Anthony Williams
anthony at justsoftwaresolutions.co.uk
Mon Dec 15 21:31:13 GMT 2008
At Mon 15 Dec 2008 19:16:20 UTC, Alexander Terekhov
<alexander.terekhov at gmail.com> wrote:
> On Mon, Dec 15, 2008 at 6:37 PM, Anthony Williams
> <anthony at justsoftwaresolutions.co.uk> wrote:
>>> int data; //= 0
>>> atomic<int> x; //= 0
>>>
>>> thread 1:
>>> ------------
>>> data = 1;
>>> x.store(1, release);
>>>
>>> thread 2:
>>> ------------
>>> if (x.load(relaxed)) {
>>> atomic_thread_fence(memory_order_acquire); // redundant
>>> data = 2;
>>> }
>>
>> Under the current C++0x memory model, the fence is not redundant, it is
>> required. Control dependencies don't create happens-before relationships
>> between threads; only release-acquire pairings can do that.
>>
>> On some current processor architectures it is not required, but that's a
>> different issue.
>
> Just out of curiosity, are you aware of any processor architecture
> specs discussing the example above and insisting on having the fence?
No. However, I'm well aware that there are many processor
architectures for which I've never seen the specs, and other
architectures that I've never even heard of.
Anthony
--
Anthony Williams
Custom Software Development | http://www.justsoftwaresolutions.co.uk
Just Software Solutions Ltd, Registered in England, Company Number 5478976.
Registered Office: 15 Carrallack Mews, St Just, Cornwall, TR19 7UL, UK
More information about the cpp-threads
mailing list