Boost logo

Boost :

Subject: Re: [boost] boost.lockfree update
From: Christian Holmquist (c.holmquist_at_[hidden])
Date: 2010-07-23 16:37:47


>> > bool enqueue(T const & t);
>> > Shouldn't this function throw an exception if t cannot be enqueued?
>>
>> i would prefer not to throw an exception! if a constant-size freelist is
>> used, the enqueue operation may fail, although no `error' occurred. i
>> prefer
>> this interface
>>
>>
>>
> If memory for the operation cannot be obtained, I believe common practice
> is to throw an exception. IMO, it does not matter if a fixed size pool is
> exhausted or the global heap, since the effect is the same -> a no op.
> With current interface I'd need to always check return value for every
> enqueue for out of memory conditions, something I don't need to do with any
> other container.
>

The following doesn't look correct to me: If pool.allocate() is not supposed
to throw an exception, you're constructing a node on a null pointer.

    node * alloc_node(void)
    {
        node * chunk = pool.allocate();
        new(chunk) node(); <---------- chunk may be 0?
        return chunk;
    }

 Also, the code requires T to be default constructible. I think something
like this would work:

node* alloc_node(T const& v)
{
        node * chunk = pool.allocate();
        if(chunk)
        {
           new(chunk) node(v);
        }
        return chunk;
}

/ christian


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