A cell whose value can only be accessed by a owning thread. Much like a Mutex but without blocking locks. Access to ThreadCells is passed cooperatively between threads.

Semantics

ThreadCell

A ThreadCell and references therof can always be send to other threads

Threads that do not own a ThreadCell and access its value will panic. There are 'try_*' variants in the API that will not panic but return a bool or Option instead.

Guard

threadcell::Guard and threadcell::GuardMut are optional and handle proper acquire/release for thradcells. There can be only one guard active per threadcell.

Guards implement Deref and DerefMut making accessing threadcells more ergonomic.

A side effect of being optional is that becomes possible to explicitly release a ThreadCell while it still has a active guard. Dereferencing such a Guard will panic then. Thus care should be taken than threadcells are either managed by guards or manually managed.

Use Cases