Boost logo

Boost :

From: Hurd, Matthew (hurdm_at_[hidden])
Date: 2003-11-17 17:14:02

> On Behalf Of Philippe A. Bouchard
> Sent: Tuesday, 18 November 2003 8:39 AM
> Subject: [boost] Re: Re: problem with shared_ptr
> Peter Dimov wrote:
> [...]
> >> Try
> >>
> >>
> Microsoft's compiler seems to support more than 1 processor... even
> efficiently:
> us/dllproc/bas
> e/interlockedincrementacquire.asp

That link seems to suggest it is good for Windows Server 2003 only...
Is that the case?

InterlockedIncrement suggests it supports

Client: Included in Windows XP, Windows 2000 Professional, Windows NT
Workstation, Windows Me, Windows 98, and Windows 95.
Server: Included in Windows Server 2003, Windows 2000 Server, and
Windows NT Server.

For win32 the fastest approach I've found is to turn on the using
intrinsics optimization for win32... though your mileage may vary. Also
be warned I've found a roughly 3 to 1 difference between AMD and Intel
P4s on this because of the processor differences.

This snippet redefines your InterlockedIncrement to use the intrinsic
implementation with no real overhead when optimized.

extern "C"
    LONG __cdecl _InterlockedIncrement(LONG volatile *Addend);

#pragma intrinsic (_InterlockedIncrement)
#define InterlockedIncrement _InterlockedIncrement

Then perhaps something long the lines of this:

class atomic_op
  template< typename word_size_type>
  static word_size_type inc(word_size_type& v)
       assert(sizeof(word_size_type) == sizeof(LONG));
       return InterlockedIncrement (reinterpret_cast< LONG volatile *>(
&v ) );

et cetera...

At the end of the day you only get tens of millions of increments a
second for multithreaded code versus some billions per second for single
thread increments using ++ ;-)


Matt Hurd

Susquehanna Pacific P/L

IMPORTANT: The information contained in this email and/or its attachments is confidential. If you are not the intended recipient, please notify the sender immediately by reply and immediately delete this message and all its attachments. Any review, use, reproduction, disclosure or dissemination of this message or any attachment by an unintended recipient is strictly prohibited. Neither this message nor any attachment is intended as or should be construed as an offer, solicitation or recommendation to buy or sell any security or other financial instrument. Neither the sender, his or her employer nor any of their respective affiliates makes any warranties as to the completeness or accuracy of any of the information contained herein or that this message or any of its attachments is free of viruses.

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