ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
ADS::LockFreePriorityQueue< K, T, Less >::Handle Class Reference

the access of one thread to a LockFreePriorityQueue: its record of the epochs, the generator of its heights and the counter of its stamps More...

#include <ADS/concurrent/LockFreePriorityQueue.h>

Public member functions

 Handle (Handle &&o) noexcept
 the record moved, the other handle left without one
 Handle (const Handle &)=delete
 no copy, since a record has one owner
Handle & operator= (const Handle &)=delete
 no assignment, since a record has one owner
Handle & operator= (Handle &&)=delete
 no assignment, since a record has one owner
 ~Handle ()
 the record given back to the queue, for another handle
void insert (K k, T x)
 inserts the pair \( ( k , x ) \), linearizable at the compare-and-swap that links its node at level 0
std::optional< Entry > tryDeleteMin (void)
 the pair of least key, removed; nothing if the queue was empty at the linearization point
std::optional< K > tryMinKey (void)
 the least key, linearizable at the read of the first pointer of level 0 not marked; nothing if the queue was empty there
bool empty (void)
 whether the queue was empty at the linearization point of tryMinKey()
const Counts & counts (void) const
 what the handle counted so far

Friends

class LockFreePriorityQueue

Detailed description

template<class K, class T, class Less = std::less< K >>
class ADS::LockFreePriorityQueue< K, T, Less >::Handle

the access of one thread to a LockFreePriorityQueue: its record of the epochs, the generator of its heights and the counter of its stamps

Constructor and destructor documentation

◆ Handle() [1/2]

template<class K, class T, class Less = std::less< K >>
ADS::LockFreePriorityQueue< K, T, Less >::Handle::Handle ( Handle && o)
noexcept

the record moved, the other handle left without one

◆ Handle() [2/2]

template<class K, class T, class Less = std::less< K >>
ADS::LockFreePriorityQueue< K, T, Less >::Handle::Handle ( const Handle & )
delete

no copy, since a record has one owner

◆ ~Handle()

template<class K, class T, class Less = std::less< K >>
ADS::LockFreePriorityQueue< K, T, Less >::Handle::~Handle ( )

the record given back to the queue, for another handle

Member function documentation

◆ counts()

template<class K, class T, class Less = std::less< K >>
const Counts & ADS::LockFreePriorityQueue< K, T, Less >::Handle::counts ( void ) const
inlinenodiscard

what the handle counted so far

◆ empty()

template<class K, class T, class Less = std::less< K >>
bool ADS::LockFreePriorityQueue< K, T, Less >::Handle::empty ( void )
inlinenodiscard

whether the queue was empty at the linearization point of tryMinKey()

◆ insert()

template<class K, class T, class Less = std::less< K >>
void ADS::LockFreePriorityQueue< K, T, Less >::Handle::insert ( K k,
T x )

inserts the pair \( ( k , x ) \), linearizable at the compare-and-swap that links its node at level 0

In pseudocode (Lindén and Jonsson, with our test of a successor before the node, beyond the book), \( d( p ) \) the mark of \( p.\mathit{next}[ 0 ] \), i.e., the delete flag of the node after \( p \), and \( \kappa = ( k , \text{the stamp} ) \) the key made distinct:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{procedure}\ \mathrm{insert}( k , x ) \cr 2 & \quad n \gets \text{a node } ( \kappa , x ) \text{ of height } h \text{, drawn with probability } 2^{-h};\ n.\mathit{inserting} \gets \mathit{true} \cr 3 & \quad \textbf{repeat}\ ( P , S ) \gets \mathrm{locate}( \kappa ); \ n.\mathit{next}[ 0 ] \gets S_0 \cr 4 & \quad \textbf{until}\ \mathrm{CAS}( P_0.\mathit{next}[ 0 ] , \langle S_0 , 0 \rangle , \langle n , 0 \rangle )\quad \triangleright\ \text{the linearization point} \cr 5 & \quad i \gets 1 \cr 6 & \quad \textbf{while}\ i < h\ \textbf{do} \cr 7 & \qquad \textbf{if}\ d( n )\ \textbf{or}\ \mathrm{behind}( S_i , n ) \ \textbf{then break}\quad \triangleright\ n \text{ deleted, or } S_i \text{ maybe before } n \cr 8 & \qquad n.\mathit{next}[ i ] \gets S_i \cr 9 & \qquad \textbf{if}\ \mathrm{CAS}( P_i.\mathit{next}[ i ] , S_i , n )\ \textbf{then}\ i \gets i + 1 \cr 10 & \qquad \textbf{else}\ ( P , S ) \gets \mathrm{locate}( \kappa ); \ \textbf{if}\ S_0 \ne n\ \textbf{then break} \cr 11 & \quad n.\mathit{inserting} \gets \mathit{false} \cr 12 & \textbf{function}\ \mathrm{locate}( \kappa ) \cr 13 & \quad p \gets \mathit{head} \cr 14 & \quad \textbf{for}\ i \gets L - 1\ \textbf{downto}\ 0\ \textbf{do} \cr 15 & \qquad c \gets p.\mathit{next}[ i ] \cr 16 & \qquad \textbf{while}\ c.\kappa < \kappa\ \textbf{or}\ d( c ) \ \textbf{or}\ ( i = 0\ \textbf{and}\ d( p ) )\ \textbf{do} \ p \gets c;\ c \gets p.\mathit{next}[ i ] \cr 17 & \qquad P_i \gets p;\ S_i \gets c \cr 18 & \quad \textbf{return}\ ( P , S ) \cr 19 & \textbf{function}\ \mathrm{behind}( c , n ) \cr 20 & \quad \textbf{if}\ c = \mathit{tail}\ \textbf{then return} \ \mathit{false} \cr 21 & \quad \langle f , m \rangle \gets c.\mathit{next}[ 0 ] \cr 22 & \quad \textbf{return}\ m\ \textbf{or}\ f = n\ \textbf{or}\ ( f \ne \mathit{tail}\ \textbf{and}\ f.\kappa < n.\kappa ) \end{array}} \]

where the tail has the greatest key and is never deleted.

◆ operator=() [1/2]

template<class K, class T, class Less = std::less< K >>
Handle & ADS::LockFreePriorityQueue< K, T, Less >::Handle::operator= ( const Handle & )
delete

no assignment, since a record has one owner

◆ operator=() [2/2]

template<class K, class T, class Less = std::less< K >>
Handle & ADS::LockFreePriorityQueue< K, T, Less >::Handle::operator= ( Handle && )
delete

no assignment, since a record has one owner

◆ tryDeleteMin()

template<class K, class T, class Less = std::less< K >>
std::optional< Entry > ADS::LockFreePriorityQueue< K, T, Less >::Handle::tryDeleteMin ( void )

the pair of least key, removed; nothing if the queue was empty at the linearization point

In pseudocode (Lindén and Jonsson, with the bit of the cut of our variant, beyond the book), with the notation of insert() above and \( b \) = offset():

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{tryDeleteMin}() \cr 2 & \quad x \gets \mathit{head};\ o \gets 0;\ \mathit{nh} \gets \mathrm{nil};\ \mathit{obs} \gets \mathit{head}.\mathit{next}[ 0 ] \cr 3 & \quad \textbf{loop} \cr 4 & \qquad o \gets o + 1;\ \langle y , m \rangle \gets x.\mathit{next}[ 0 ] \cr 5 & \qquad \textbf{if}\ y = \mathit{tail}\ \textbf{then return nil} \quad \triangleright\ \text{empty: linearized at this read} \cr 6 & \qquad \textbf{if}\ \mathit{nh} = \mathrm{nil}\ \textbf{and} \ x.\mathit{inserting}\ \textbf{then}\ \mathit{nh} \gets x \cr 7 & \qquad \textbf{if not}\ m\ \textbf{then}\ \langle y , m \rangle \gets \mathrm{FAO}( x.\mathit{next}[ 0 ] , 1 )\quad \triangleright \ \text{the linearization point if } m = 0 \cr 8 & \qquad x \gets y;\ \textbf{if not}\ m\ \textbf{then break} \cr 9 & \quad e \gets ( x.k , x.x )\text{, the item moved out}; \ \textbf{if}\ \mathit{nh} = \mathrm{nil}\ \textbf{then}\ \mathit{nh} \gets x \cr 10 & \quad \textbf{if}\ o > b\ \textbf{and}\ \mathit{obs} \text{ has no cut bit}\ \textbf{and}\ \mathit{nh} \ne \mathit{obs}\ \textbf{and} \ \mathrm{CAS}( \mathit{head}.\mathit{next}[ 0 ] , \mathit{obs} , \langle \mathit{nh} , 1 , \mathit{cut} \rangle )\ \textbf{then} \cr 11 & \qquad \mathrm{restructure}();\ \text{clear the cut bit} \cr 12 & \qquad \text{retire the nodes from } \mathit{obs} \text{ to } \mathit{nh} \text{, the latter excluded} \cr 13 & \quad \textbf{return}\ e \cr 14 & \textbf{procedure}\ \mathrm{restructure}() \cr 15 & \quad i \gets L - 1;\ p \gets \mathit{head} \cr 16 & \quad \textbf{while}\ i > 0\ \textbf{do} \cr 17 & \qquad h \gets \mathit{head}.\mathit{next}[ i ];\ c \gets p.\mathit{next}[ i ]\quad \triangleright\ \text{in this order} \cr 18 & \qquad \textbf{if not}\ d( h )\ \textbf{then}\ i \gets i - 1; \ \textbf{continue} \cr 19 & \qquad \textbf{while}\ d( c )\ \textbf{do}\ p \gets c;\ c \gets p.\mathit{next}[ i ] \cr 20 & \qquad \textbf{if}\ \mathrm{CAS}( \mathit{head}.\mathit{next}[ i ] , h , c )\ \textbf{then}\ i \gets i - 1 \end{array}} \]

◆ tryMinKey()

template<class K, class T, class Less = std::less< K >>
std::optional< K > ADS::LockFreePriorityQueue< K, T, Less >::Handle::tryMinKey ( void )

the least key, linearizable at the read of the first pointer of level 0 not marked; nothing if the queue was empty there

◆ LockFreePriorityQueue

template<class K, class T, class Less = std::less< K >>
friend class LockFreePriorityQueue
friend

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