festival icon indicating copy to clipboard operation
festival copied to clipboard

Less locks, more atomics

Open hinto-janai opened this issue 1 year ago • 1 comments

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 clears AUDIO_STATE's` queue
  • GUI reads AUDIO_STATE, empty queue but still playing?
  • Audio sets playing to false

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.

hinto-janai avatar Jun 24 '23 16:06 hinto-janai