|
Boost : |
Subject: Re: [boost] [lock-free] CDS -yet another lock-free library
From: Giovanni Piero Deretta (gpderetta_at_[hidden])
Date: 2010-03-30 13:49:39
On Tue, Mar 30, 2010 at 4:19 PM, Khiszinsky, Maxim
<Maxim.Khiszinsky_at_[hidden]> wrote:
> Helge Bahmann wrote:
>
[snip]
>
> - infinite loop in spinlock on atomic64_t.
>
> However, Peter Dimov's advice corrected the error - volatile! Yes!
> This code
>
> static inline atomic64_t load64( atomic64_t volatile const * pMem )
> {
> // Atomically loads 64bit value by SSE intrinsics
> __m128i volatile v = _mm_loadl_epi64( (__m128i const *) pMem ) ;
> return v.m128i_i64[0] ;
> }
>
Shouldn't volatile go in the cast and not in v? It is fine if v is
stored in a register, but you want the read to pMem not to be cached.
What you are doing with the cast right now is casting away
volatile-ness in addition of changing the type of the pointed object.
The fact that it is now working is probably just due to the fact that
the compiler is confused: the compiler is still free to hoist the
loads from pmem, as long as all stores and loads to v (which is in the
stack) are done.
-- gpd
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk