Boost logo

Boost :

Subject: Re: [boost] [interprocess] atomic_write32 on GCC/x86/x68_64 lacks memory barrier
From: Peter Dimov (lists_at_[hidden])
Date: 2014-08-11 08:34:12


Lars Hagström wrote:

> inline void atomic_write32(volatile boost::uint32_t *mem, boost::uint32_t
> val)
> {
> __asm__ __volatile__ ( "" ::: "memory" );
> __asm__ (
> "xchgl %0, %1"
> : "+r" (val), "+m" (*mem)
> );
> __asm__ __volatile__ ( "" ::: "memory" );
> }

This will work, but it's more verbose than it needs to be. You can put the
__volatile__ and "memory" on the xchg asm statement and take out the two
others.

You'll also need to fix atomic_read32:

{
    uint32 r = *mem;
    __asm__ __volatile__ ( "" ::: "memory" );
    return r;
}


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk