ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
ADS::MinBoard< K > Class Template Reference

the least of the keys of \( p \) threads, one slot of a line of cache per thread, published and read by relaxed accesses More...

#include <ADS/concurrent/MinBoard.h>

Public types

using Key = K
 the type of the keys

Public member functions

 MinBoard (std::size_t p, K k=std::numeric_limits< K >::max())
 the board of \( p \) slots, each holding \( k \) (by default the largest key, which no published key is above)
std::size_t size (void) const
 the number \( p \) of the slots
void publish (std::size_t i, K k)
 \( k \) in the slot \( i \), by a relaxed store made only if the slot holds another key, read by a relaxed load
K at (std::size_t i) const
 the key of the slot \( i \), by a relaxed load
K min (void) const
 the least of the keys read in the slots, one relaxed load each: a value of each slot not older than those that happen before the call, not a snapshot of the board
void reset (K k=std::numeric_limits< K >::max())
 every slot set to \( k \)

Static public attributes

static constexpr std::size_t kLine = 64
 the bytes of a slot, a line of cache

Detailed description

template<class K>
requires ( std::totally_ordered< K > && std::is_trivially_copyable_v< K > )
class ADS::MinBoard< K >

the least of the keys of \( p \) threads, one slot of a line of cache per thread, published and read by relaxed accesses

Member typedef documentation

◆ Key

template<class K>
using ADS::MinBoard< K >::Key = K

the type of the keys

Constructor and destructor documentation

◆ MinBoard()

template<class K>
ADS::MinBoard< K >::MinBoard ( std::size_t p,
K k = std::numeric_limits< K >::max() )
inlineexplicit

the board of \( p \) slots, each holding \( k \) (by default the largest key, which no published key is above)

Precondition
\( p \ge 1 \)

Member function documentation

◆ at()

template<class K>
K ADS::MinBoard< K >::at ( std::size_t i) const
inlinenodiscard

the key of the slot \( i \), by a relaxed load

Precondition
\( i < p \)

◆ min()

template<class K>
K ADS::MinBoard< K >::min ( void ) const
inlinenodiscard

the least of the keys read in the slots, one relaxed load each: a value of each slot not older than those that happen before the call, not a snapshot of the board

In pseudocode (beyond the book):

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{min}() \cr 2 & \quad m \gets S[ 0 ] \cr 3 & \quad \textbf{for}\ i \gets 1\ \textbf{to}\ p - 1\ \textbf{do} \ m \gets \min( m , S[ i ] )\quad \triangleright\ \text{relaxed} \cr 4 & \quad \textbf{return}\ m \end{array}} \]

◆ publish()

template<class K>
void ADS::MinBoard< K >::publish ( std::size_t i,
K k )
inline

\( k \) in the slot \( i \), by a relaxed store made only if the slot holds another key, read by a relaxed load

In pseudocode (beyond the book):

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{procedure}\ \mathrm{publish}( i , k ) \cr 2 & \quad \textbf{if}\ S[ i ] \ne k\ \textbf{then}\ S[ i ] \gets k \quad \triangleright\ \text{relaxed, the line written only then} \end{array}} \]

Precondition
\( i < p \); the caller is the only writer of the slot

◆ reset()

template<class K>
void ADS::MinBoard< K >::reset ( K k = std::numeric_limits< K >::max())
inline

every slot set to \( k \)

Precondition
no other thread accesses the board

◆ size()

template<class K>
std::size_t ADS::MinBoard< K >::size ( void ) const
inlinenodiscard

the number \( p \) of the slots

Member data documentation

◆ kLine

template<class K>
std::size_t ADS::MinBoard< K >::kLine = 64
staticconstexpr

the bytes of a slot, a line of cache


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