Concurrent auto-swapping double buffer
Warning: Until this crate reaches version
1.0it should be considered WIP-grade.
This crate provides a double buffer. Differences to existing implementations:
- Unlike channels, the access is by-reference and not by-value
- Thread-safe (no need for additional synchronization, with the double buffer providing interior-mutability by default)
- Auto-swapping: Whenever the writer finishes writing, the buffers are swapped on the next possible opportunity (when no readers or writers are active)
no_stdcompatible (needs acritical_sectionimplementation)
Usage:
use *;
let mut db: = new;
let = db.init;
let mut writer = back.write;
let reader = front.read;
// Both are initialized with the default value
assert_eq!;
assert_eq!;
*writer = 5;
drop;
drop;
// the buffers are swapped now!
let reader = front.read;
assert_eq!;