|
Boost : |
Subject: Re: [boost] [Block Pointer] Review Request
From: Emil Dotchevski (emildotchevski_at_[hidden])
Date: 2011-05-02 16:08:56
On Mon, May 2, 2011 at 1:02 PM, Phil Bouchard <philippe_at_[hidden]> wrote:
> On 5/2/2011 12:49 PM, Emil Dotchevski wrote:
>>
>> Then, what is the benefit of block_ptr compared to using raw pointers
>> as cyclic references? Maybe I'm missing something but aren't they
>> equally (un)safe?
>
> I haven't considered this scenario when block_ptr are explicitly
> dereferenced in the destructor. Maybe I can add a function that can be
> called explicitly to check whether the pointee is cyclic and has already
> been destroyed.
Keep in mind multi-threading issues too. The way the shared_ptr
framework deals with this is that weak_ptr::lock() returns a
shared_ptr, so if the object hasn't yet expired at the time lock() is
called, it can't expire later (since the returned shared_ptr keeps it
afloat.) This is what makes using weak_ptr for cyclic references safe.
Emil Dotchevski
Reverge Studios, Inc.
http://www.revergestudios.com/reblog/index.php?n=ReCode
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk