$include_dir="/home/hyper-archives/boost/include"; include("$include_dir/msg-header.inc") ?>
From: William Kempf (sirwillard_at_[hidden])
Date: 2000-08-31 10:28:10
--- In boost_at_[hidden], "Bill Wade" <bill.wade_at_s...> wrote:
> > From: William Kempf [mailto:sirwillard_at_m...]
> 
> > 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
> zero).
> Exchange
> 
> The following Win32 functions don't work right on Win95:
> 
> InterlockedCompareExchange
> InterlockedCompareExchangePointer
> InterlockedExchangeAdd
But they do on Win98.  Tricky issue here.  I included the 
compare_exchange() only to bring up debate about its usefulness.  
I've never found a need for them, but didn't want to eliminate them 
just because I've never needed them, nor because Win95 didn't support 
them.  Obviously they can be added to Win95 in the form of some 
assembler instructions.
> On more recent versions of Windows Increment and Decrement return 
the
> result, not just the sign.
I got this one wrong :(.  I thought it was an NT/9x discrepency, but 
you're right, it's an hitorical discrepency.  In any event, for 
portability the best we can hope for is being able to check for 0, 
>0, <0... and it may be that we can only check for 0.
 
> 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 counter is used for much more than just ref-counting.
 
> > 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
> tested).
I see no InterlockedRead.  I'm not referring to 
InterlockedExchangeAdd, but to InterlockedExchange.  I never even 
mentioned InterlockedExchangeAdd.  InterlockedExchange exchanges two 
long's, thus is used for both reading and writing.  I doubt that if 
there is a "read" method beyond InterlockedExchange that it's any 
faster, let alone 3 times.
Bill Kempf