pub struct RacyCell<T>(/* private fields */);
Expand description
Cell type that should be preferred over a static mut
is better to use in a
static
Based on @bstrie comment [issue-53639-bstrie]: https://github.com/rust-lang/rust/issues/53639#issuecomment-888435728
§Safety
The idea here being that callers of RacyCell::get
could only turn that *mut into a reference,
if you can guarantee the usual reference safety invariants as demonstrated in
this example for UnsafeCell::get,
with the added rub that you also have to uphold those invariants while taking threads into account,
which means that almost nobody can actually safely cast this *mut to a reference
(which helps to illustrate the problem with static mut here),
so you’re better off just working with the raw pointer
(ideally by wrapping it in your own synchronization logic).