Modify

Opened 5 years ago

Closed 5 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?

Attachments (0)

Change History (1)

comment:1 Changed 5 years ago by timblechmann

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

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain timblechmann.
The resolution will be deleted.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.