Boost logo

Boost :

Subject: Re: [boost] [interprocess] atomic_write32 on GCC/x86/x68_64 lacks memory barrier
From: Lars Hagström (lars_at_[hidden])
Date: 2014-08-11 09:21:43


Thanks!

As I said, I'm not an assembly programmer. I can copy/paste though, which
lead to the verbosity. :-)

On Mon, Aug 11, 2014 at 2:34 PM, Peter Dimov <lists_at_[hidden]> wrote:

> 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;
>
> }
>
> _______________________________________________
> Unsubscribe & other changes: http://lists.boost.org/
> mailman/listinfo.cgi/boost
>


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