| Taskflow: A General-purpose Task-parallel Programming System

Loading...
Searching...
No Matches
Public Types | Public Member Functions | Public Attributes | List of all members
tf::TaggedHead128 Struct Reference

tagged free-list head using a 128-bit (pointer, version) pair More...

`#include <taskflow/utility/object_pool.hpp>`

## Public Types
using | pointer_type = uintptr_t
| block address representation
using | tag_type = uintptr_t
| ABA version counter representation.

## Public Member Functions
| TaggedHead128 ()=default
| constructs a null, zero-tagged head
| TaggedHead128 (pointer_type p, tag_type t) noexcept
| constructs a head with an explicit block address and version counter
pointer_type | get_ptr () const noexcept
| returns the stored block address
tag_type | get_tag () const noexcept
| returns the ABA version counter

## Public Attributes
pointer_type | ptr {0}
| block address (reinterpret-cast to/from `ObjectBlock*`)
tag_type | tag {0}
| ABA version counter; incremented on every push and pop.

## Detailed Description

tagged free-list head using a 128-bit (pointer, version) pair

TaggedHead128 stores the free-list head pointer and an ABA version counter as two independent 64-bit words, yielding a 16-byte representation. `std::atomic<TaggedHead128>` requires a 128-bit compare-and-swap: CMPXCHG16B on x86-64 or CASP on ARMv8.1+. On platforms that lack a native 128-bit CAS (e.g. RISC-V, baseline ARMv8.0), the atomic falls back to a lock-based implementation — still correct, but no longer lock-free.

The full 64-bit version counter makes ABA wrap-around effectively impossible under any realistic workload.

// explicitly select the 128-bit head (this is also the default)
tf::ObjectPool<MyTask, 5, tf::TaggedHead128> pool;
tf::ObjectPool
sharded fixed-size object allocator with a lock-free hot path
Definition object_pool.hpp:408

See also
  TaggedHead64 for an 8-byte alternative that is lock-free on all 64-bit platforms at the cost of a narrower version counter.

## Constructor & Destructor Documentation

## ◆ TaggedHead128()

tf::TaggedHead128::TaggedHead128 | ( | pointer_type | p,
|  | tag_type | t )
| inline noexcept

constructs a head with an explicit block address and version counter

Parameters

  p | block address as `uintptr_t`
  t | ABA version counter

tf::TaggedHead128 head(reinterpret_cast<uintptr_t>(block), 0);
tf::TaggedHead128
tagged free-list head using a 128-bit (pointer, version) pair
Definition object_pool.hpp:45

## Member Function Documentation

## ◆ get_ptr()

pointer_type tf::TaggedHead128::get_ptr | ( |  | ) | const
| inline noexcept

returns the stored block address

tf::TaggedHead128 head(reinterpret_cast<uintptr_t>(block), 7);
auto p = head.get_ptr(); // p == reinterpret_cast<uintptr_t>(block)

## ◆ get_tag()

tag_type tf::TaggedHead128::get_tag | ( |  | ) | const
| inline noexcept

returns the ABA version counter

tf::TaggedHead128 head(reinterpret_cast<uintptr_t>(block), 7);
auto t = head.get_tag(); // t == 7

The documentation for this struct was generated from the following file:

- taskflow/utility/object_pool.hpp