festival
festival copied to clipboard
Less locks, more atomics
What
There are some key global data structures that have static
lifetime.
E.g, AUDIO_STATE
, RESET_STATE
.
Atomics are simpler, easier to use, more performant, and won't ever deadlock.
Although these global structures aren't fully compatible with atomics, and there will be data races if the whole structure isn't updated atomically, e.g:
-
GUI
requests to clear queue and stop playback -
Audio
clearsAUDIO_STATE
's` queue -
GUI
readsAUDIO_STATE
, empty queue but still playing? -
Audio
setsplaying
tofalse
The whole struct should be updated at once before any other thread can read it as a whole.
Todo
Either shard the current structures in a well defined way, or use something like AtomicCell
.
https://github.com/hinto-janai/someday is the main data sharing primitive in https://github.com/hinto-janai/sansan (which will eventually replace shukusai/src/audio
).
It uses lock-free MVCC, and atomically updates the entire structure at once.