Marsyas
0.6.0-alpha
|
Thread-safe lock-free exchange of large data. More...
#include <stage.h>
Public Member Functions | |
T & | back () |
void | clear (const T &initial_value=T()) |
NOT THREAD-SAFE. | |
T & | front () |
bool | has_front () const |
void | pop () |
void | push () |
stage (const T &initial_value=T()) |
Thread-safe lock-free exchange of large data.
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.
void clear | ( | const T & | initial_value = T() | ) | [inline] |