Marsyas  0.5.0-beta1
Public Member Functions
stage< T > Class Template Reference

Thread-safe lock-free exchange of large data. More...

#include <stage.h>

Public Member Functions

T & back ()
void clear (const T &initial_value=T())
T & front ()
bool has_front () const
void pop ()
void push ()
 stage (const T &initial_value=T())

Detailed Description

template<typename T>
class Marsyas::RealTime::stage< T >

Thread-safe lock-free exchange of large data.

Jakob Leben <>

This class facilitates lock-free exchange of large data between a single producer thread and a single consumer thread, in a functionaly similar manner to an atomic variable. . It is ensured that the producer can always write new data (never needs to wait), and that the consumer always sees the latest data, but some data may be lost if it is not consumed before more data is produced.

The class holds an internal array of 3 instances of the template parameter type. A reference to one of them is provided to the consumer and another one to the producer. The third data space is used for exchange - it is a kind of staging area: when the producer is finished writing to its space, it uses push() to exchange that space with the staging space, and when the consumer is finished using its space it uses pop() to exchange it with the staging space.

By only exchanging references to data, data types of any complexity and size can be passed between threads in a lock-free manner, at the cost of keeping 3 times the size of the individual data space.

Definition at line 57 of file stage.h.

Constructor & Destructor Documentation

stage ( const T &  initial_value = T()) [inline]

Definition at line 72 of file stage.h.

Member Function Documentation

T& back ( ) [inline]

Definition at line 92 of file stage.h.

void clear ( const T &  initial_value = T()) [inline]


Definition at line 83 of file stage.h.

T& front ( ) [inline]

Definition at line 108 of file stage.h.

bool has_front ( ) const [inline]

Definition at line 103 of file stage.h.

void pop ( ) [inline]

Definition at line 115 of file stage.h.

void push ( ) [inline]

Definition at line 97 of file stage.h.

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