Boost logo

Boost :

From: Andy Glew (glew_at_[hidden])
Date: 1999-12-26 18:30:29

> > if (--*pn == 0) { delete px; }
> Well, if everything is OK up to that point, you'll have a leak, not a
> double-deletion, because there will never be fewer references than
> shared_ptrs needing to be destroyed.

A compiler can legally implement this as (in pseudocode):

    treg1 := mem( *pn )
    treg2 := sub( treg1 - 1 )
    mem( *pn ) := treg2
    treg3 := mem( *pn )
    if( treg3 != 0 ) goto 1f
        ...delete px

Note that if this is done, then 2 threads can both
execute the decrement, and both arrive at the
load into treg3 at the same time, leading to a double

Now, most compilers will avoid the treg3 load,
using the treg2 value in the compare,
so that Dave's statement will be true on most systems.
But, it doesn't have to be so. Which is half of the fun
of multothreading, isn't it?



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