Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2006-10-21 22:30:32


Chris Thomasson wrote:

> The basic technique for 'copying' is as follows:
>
> rc* copy(rc **sloc, int count) {
> 1: load ptr from *sloc
> if ptr is null goto 2
> lock spinlock associated with ptr
> re-load ptr from *sloc
> compare w/ previous load
> if not equal unlock and goto 1
> XADD ptr's with count
> * if the previous value was less than 1 unlock and goto 1
> unlock
> 2: return ptr
> }

I thought that that might be the case. Won't you need to undo the XADD
before unlocking and retrying, though? That, or use CAS. The decrement
thread may not care, but if another increment thread gets in first, bad
things happen; or am I missing something else?

> IMHO, anytime you can reduce the number of atomic operations and/or memory
> barriers is a plus...

Maybe... Given a choice between the two, I would prefer to somehow eliminate
the spinlock in 'copy', though. :-)


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