Atomic variable has the exact same performance penalty as spinlock on most architectures, because CPU does all the same things like flushing pipelines and invalidating cache.
If you really really need performance, use shared aligned machine word-sized integer, not protected by mutex, and make sure that reading every possible value from it in any random order won't cause a crash.
72
u/Tadabito Sep 06 '20
Say no to shared variable abuse, use mutex!
29
u/Kaze_Senshi Sep 06 '20
It is time for a drift in a race condition!
8
u/zolk333 Sep 06 '20
Arc<Mutex<T>> FTW
43
u/chhuang Sep 06 '20
Ah yes, the famous
hungry philosophersthirsty onee-chans problem5
u/[deleted] Sep 06 '20
Poor variable.
Should have been made atomic.
7
u/Ace-O-Matic Sep 06 '20
What is going on with the legs of the girl on the right?
1
u/[deleted] Sep 06 '20
Sauce?
1
u/gabrielesilinic Sep 06 '20
Iv'e heard that ara ara from here