Atomic*::get_mut() uses UnsafeCell to mutate the value directly, so Atomic*::get_mut() is only safe if it's called from a single thread. If Atomic*::get_mut() is called from multiple threads, or Atomic* is accessible as mutable references in different threads, it will cause the data race.
Thus, for all the Atomic* in the current code, the *.get_mut() should be replaced by *.store() to avoid the data race. This change will solve the data race found by ThreadSanitizer(#34).
Atomic*::get_mut()
usesUnsafeCell
to mutate the value directly, soAtomic*::get_mut()
is only safe if it's called from a single thread. IfAtomic*::get_mut()
is called from multiple threads, orAtomic*
is accessible as mutable references in different threads, it will cause the data race. Thus, for all theAtomic*
in the current code, the*.get_mut()
should be replaced by*.store()
to avoid the data race. This change will solve the data race found by ThreadSanitizer(#34).