Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#7767 closed Bugs (invalid)

lockfree queue allocation problem

Reported by: pn.suzuki.kojiro@… Owned by: timblechmann
Milestone: To Be Determined Component: lockfree
Version: Boost Development Trunk Severity: Problem
Keywords: Cc:

Description

The default constructor of boost::lockfree::queue<int>
try to allocate 0xffffffffffffffff elements for pool.

Revision: 81719, queue.hpp, line 154

        pool(node_allocator(), capacity)

"capacity" is 0xffffffffffffffff in my environment(VS 2012 Express for Desktop).

The other constructors works fine.

The problem occurred on both of 32bit and 64bit.
(in 32bit, the "capacity" was 0xffffffff)

Change History (6)

comment:1 by timblechmann, 10 years ago

Resolution: invalid
Status: newclosed

not a bug: you have not configured the queue to have a capacity that is specified at compile time, so you should not use the default constructor. there is a run-time assertion, but unfortunately that fires after the memory pool is constructed with -1, which is a bit confusing. let me see, if i can improve that a bit ...

comment:2 by pn.suzuki.kojiro@…, 10 years ago

Why don't you split implementation by have_capacity?

comment:3 by timblechmann, 10 years ago

possible, but increases the complexity of the code as one would need an additional abstraction layer.

comment:4 by pn.suzuki.kojiro@…, 10 years ago

I don't understand yet, why can't I use the default constructor in this case?
I thought that the default constructor should constructs empty queue with empty pool.

        pool(node_allocator(), has_capacity ? capacity : 0)

Does this code have a problem?

comment:5 by timblechmann, 10 years ago

if you don't specify a capacity, internal nodes have to be allocated during push() or pop() ... since memory allocation is not lock-free the data-structure is not lock-free anymore ...

comment:6 by Kojiro Suzuki <pn.suzuki.kojiro@…>, 10 years ago

Thank you for your answers, I understand it now.

I have an idea.
If you use the the previous code, and leave the assertion,
it generates assertion without trying to allocate huge elements.

    queue(void):
        head_(tagged_node_handle(0, 0)),
        tail_(tagged_node_handle(0, 0)),
        pool(node_allocator(), has_capacity ? capacity : 0) // add this
    {
        BOOST_ASSERT(has_capacity); // and leave this
        initialize();
    }
Note: See TracTickets for help on using tickets.