Boost logo

Boost Users :

Subject: Re: [Boost-users] [Boost.Smart_ptr] global_reset (revamp) for shared_ptr
From: John Dlugosz (JDlugosz_at_[hidden])
Date: 2009-08-19 11:07:26


> Ideally, you should have a reader-writer mutex to guard global. Lock
> it
> for read access (non-exclusive) for line A and unlock it before
> "local->foo()". Lock it for write access (exclusive) for line B.
>
> If you do not have a reader-writer mutex, then use an ordinary mutex to
> lock both line A and line B. This may, however hurt concurrency if
> line
> A is run frequently.

Since the critical section is so small, it may be more efficient to use the simplest light-duty construct possible to optimize for the case where there is no contention. That really depends on the usage in the final program, but I would expect from the description that accessing the pointer is a small part of what the program does. At the very least, it calls members via that pointer once it is obtained.

On the other hand, having the atomic increment instruction inside the critical region will lengthen it from one or two instructions you expected to more like 40, as that stalls the pipeline.

Some of my current work involves high-performance server code that even avoids these kinds of instructions.

TradeStation Group, Inc. is a publicly-traded holding company (NASDAQ GS: TRAD) of three operating subsidiaries, TradeStation Securities, Inc. (Member NYSE, FINRA, SIPC and NFA), TradeStation Technologies, Inc., a trading software and subscription company, and TradeStation Europe Limited, a United Kingdom, FSA-authorized introducing brokerage firm. None of these companies provides trading or investment advice, recommendations or endorsements of any kind. The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from any computer.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net