
On Tue, Mar 30, 2010 at 4:19 PM, Khiszinsky, Maxim <Maxim.Khiszinsky@billing.ru> 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