Opened 10 years ago

Closed 10 years ago

#8135 closed Bugs (fixed)

[lockfree] compile time capacity difference behavior

Reported by: Akira Takahashi <faithandbrave@…> Owned by: timblechmann
Milestone: To Be Determined Component: lockfree
Version: Boost 1.53.0 Severity: Problem
Keywords: Cc:

Description

http://lists.boost.org/boost-users/2013/02/77649.php

I confused with boost::lockfree::queue behavior.

Fist, run-time capacity:

#include <iostream>
#include <boost/lockfree/queue.hpp>

int main()
{
    boost::lockfree::queue<int, boost::lockfree::fixed_sized<true>> que(3);

    std::cout << std::boolalpha;

    std::cout << que.push(1) << std::endl; // true
    std::cout << que.push(2) << std::endl; // true
    std::cout << que.push(3) << std::endl; // true
    std::cout << que.push(4) << std::endl; // false
}

I think this behavior is correct.

But, compile-time capacity:

#include <iostream>
#include <boost/lockfree/queue.hpp>

int main()
{
    boost::lockfree::queue<int, boost::lockfree::capacity<3>> que;

    std::cout << std::boolalpha;

    std::cout << que.push(1) << std::endl; // true
    std::cout << que.push(2) << std::endl; // true
    std::cout << que.push(3) << std::endl; // false : why?
    std::cout << que.push(4) << std::endl; // false
}

Is this bug or specification?

Change History (1)

comment:1 by timblechmann, 10 years ago

Resolution: fixed
Status: newclosed

(In [83079]) lockfree: queue - allocate one element more than required

the queue internally uses a dummy node, which is not user-visible. therefore we should allocate one element more than needed

fixes #8135

Note: See TracTickets for help on using tickets.