Lock-free stack.
More...
#include <lock_free_stack.h>
template<typename Type, typename ValuePool = embb::containers::LockFreeTreeValuePool < bool, false >>
class embb::containers::LockFreeStack< Type, ValuePool >
Lock-free stack.
- Implemented concepts:
- Stack Concept
- Template Parameters
-
Type | Type of the stack elements |
ValuePool | Type of the value pool used as basis for the ObjectPool which stores the elements. |
template<typename Type , typename ValuePool = embb::containers::LockFreeTreeValuePool < bool, false >>
Creates a stack with the specified capacity.
- Dynamic memory allocation
- Let
t
be the maximum number of threads and x
be 1.25*t+1
. Then, x*(3*t+1)
elements of size sizeof(void*)
, x
elements of size sizeof(Type)
, and capacity
elements of size sizeof(Type)
are allocated.
- Concurrency
- Not thread-safe
- See also
- Stack Concept
- Parameters
-
[in] | capacity | Capacity of the stack |
template<typename Type , typename ValuePool = embb::containers::LockFreeTreeValuePool < bool, false >>
Destroys the stack.
- Concurrency
- Not thread-safe
template<typename Type , typename ValuePool = embb::containers::LockFreeTreeValuePool < bool, false >>
Returns the capacity of the stack.
- Returns
- Number of elements the stack can hold.
- Concurrency
- Thread-safe and wait-free
template<typename Type , typename ValuePool = embb::containers::LockFreeTreeValuePool < bool, false >>
Tries to push an element onto the stack.
- Returns
true
if the element could be pushed, false
if the stack is full.
- Concurrency
- Thread-safe and lock-free
- Note
- It might be possible to push more elements onto the stack than its capacity permits.
- See also
- Stack Concept
- Parameters
-
[in] | element | Const reference to the element that shall be pushed |
template<typename Type , typename ValuePool = embb::containers::LockFreeTreeValuePool < bool, false >>
Tries to pop an element from the stack.
- Returns
true
if an element could be popped, false
if the stack is empty.
- Concurrency
- Thread-safe and lock-free
- See also
- Stack Concept
- Parameters
-
[in,out] | element | Reference to the popped element. Unchanged, if the operation was not successful. |