Boost logo

Boost :

From: Bill Wade (bill.wade_at_[hidden])
Date: 2000-08-31 10:04:25

> From: William Kempf [mailto:sirwillard_at_[hidden]]

> I honestly don't believe you'll find an
> implementation that supports atomic operations that doesn't support
> exchange, increment and decrement.

According to MS documentation, Win95 (and early versions of NT) support the
following atomic operations on properly aligned 32 bit variables:

Full word read or write.
Increment or Decrement and get the sign (but not value) of the result (or

The following Win32 functions don't work right on Win95:


On more recent versions of Windows Increment and Decrement return the
result, not just the sign.

IIRC you can efficiently do COW (including an "unshareable" flag) on windows
using just:
  write (not necessarily atomic)
  atomic read
  atomic increment/decrement with test for zero result
Using count == 0 for unshareable you get
  CurrentlyShared(): count > 1
  Share(): Increment(count)
  Detach(): if(!CurrentlyShared() || Decrement(count) == 0) delete;
write is used only when you already know that you are unshared, such as in a
default constructor, or when changing state from unshareable to shareable.

> The exchange functions are used to get the value, for one thing ;).

On Win32 a read (which is atomic) is about three times as fast as
InterlockedExchangeAdd (at least on the Pentium family chips that I've

Boost list run by bdawes at, gregod at, cpdaniel at, john at