
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

El 08/12/2011 17:04, peter jacobsen escribió:
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
(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%2...]
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. Ion

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
(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

El 09/12/2011 11:51, Tim Blechmann escribió:
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.
Ok, for Interprocess internal purposes I just need 32 bit integer atomics (maybe 64 bit ones for 64 bit platforms), and I think every platform compatible with Interprocess (UNIX and Windows) will support them without spinlocks. I guess the solution for interprocess would be to use a spinlock per atomic variable, making sizeof(T) != sizeof(atomic<T>). I'm just thinking about ABI issues. Best, Ion
participants (3)
-
Ion Gaztañaga
-
peter jacobsen
-
Tim Blechmann