Boost logo

Boost :

From: Larry Evans (jcampbell3_at_[hidden])
Date: 2003-05-23 12:23:46


Alexander Terekhov wrote:
> Larry Evans wrote:
> [...]
>
>>weighted reference counts eliminate around half the synchronization.
>>This is because, AFAICT, the only time synchronization is needed is
>>when a smart weighted pointer releases it's pointee, but not
>>when it acquires a new pointee (because the reference count is
>>gotten from the other, or source, smart weighted pointer).
>
>
> I don't understand. Please elaborate (explain with more details...
> or simply drop a link ;-) ).
http://www.cs.kent.ac.uk/people/staff/rej/cgi-bin/searchbib?pattern=weighted+reference

Quoting from the Conlusions of "Cyclic Weighted Reference Counting":

   By associating weights with pointers, interprocessor communication
   need take place only when a pointer is deleted -- pointers may
   be copied without any communication.

I'm assuming the "thread synchronization" is analagous to the
"interprocessor communication" mentioned above, only it takes more
time.

The way it works is that each pointee begins with a some maximum reference count
(actually, log base 2 of the maximum reference count). The first smart pointer
copies this reference count. Subsequent smart pointer copies "share" the reference
count by divided it by 2 and each participant get's half. When a smart pointer
releases it's pointee, it subtracts it's weight from the count in the pointee
(and thus requires "thread synchronization" [in case of threads] or
"interprocessor communication" [in case of multiprocessing).
The invariant is that the count in the pointee = sum of the count's in all
the smart pointers referencing that pointee.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk