August 23, 2004
Anuj Goyal wrote:

> The reference counting section in STLport is not consistent (see _thread.c or
> _thread.c [can't remember the name] in the STLport/stlport/stl directory) ...
> atomic increment is supported on some platforms (win32, solaris) but not others
> (aix, linux).  If someone is interested, Alexander Terekhov has a good
> discussion of proper reference counting.  He has posted a class that is
> available on the Intel board.  C++ developers that deal with multiple platforms
> may find it useful. (PS: how much do we have to pay walter to port DMC to the
> linux platform, I bet it would beat the pants off of gcc).  D is a much better
> language, but developers still have years of C++ that need support =)
> 
> 
> http://softwareforums.intel.com/ids/board/message?board.id=42&message.id=243

As interesting as that code is, it's incomplete. Technically accurate, in terms of what kinds of memory ordering primitives should, in theory, exist on a machine. But how many architectures have such fine-grained control over memory barriers? On Intel, you're lucky to have memory fences at all. The code is good for understanding all of the various issues faced by the developer in providing atomic operations, but seems to be somewhat impractical if not augmented by the appropriate amount of inline assembly.

Personally, I tend to prefer LL/SC semantics. This is achieveable on Intel using CMPXCHG -- see Jayanti, Petrovic, "Efficient and Practical Constructions of LL/SC Variables", PODC'03 (ACM). There's some overhead associated with doing LL/SC properly, namely the tags that have to go along with the shared variables, but that's not a bad price to pay for lock-free performance.
1 2
Next ›   Last »