|
Boost Users : |
Subject: Re: [Boost-users] [interprocess] atomic_write32
From: Tim Blechmann (tim_at_[hidden])
Date: 2011-12-09 05:51:45
>> I have noticed that for Windows, atomic_write32 is defined thus:
>>
>> inline void atomic_write32(volatile boost::uint32_t *mem, boost::uint32_t
>> val)
>> { winapi::interlocked_exchange(reinterpret_cast<volatile long*>(mem), val);
>> { }
>>
>> Whereas otherwise like this:
>>
>> inline void atomic_write32(volatile boost::uint32_t *mem, boost::uint32_t
>> val)
>> { *mem = val; }
>>
>> the reads are both:
>> return *mem;
>>
>> Windows documentation states that:
>> 'Simple reads and writes to properly-aligned 32-bit variables are
>> atomic operations.'
>> [http://msdn.microsoft.com/en-
us/library/windows/desktop/ms684122%28v=vs.85%29.aspx]
>>
>> Is there a reason for this?
>
> Those operations require also memory barriers. I'm not an expert on
> atomic operations so the code might have several errors. My mid-term
> plan is to port it to Boost.Atomic.
btw, helge was planning to provide a separate implementation of boost.atomic for
interprocess, because his blocking emulation of atomics depends on a per-process
spinlock pool.
tim
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net