Crates.io | threadcell |
lib.rs | threadcell |
version | 1.0.3 |
source | src |
created_at | 2022-08-30 00:28:17.781523 |
updated_at | 2023-05-05 14:23:43.160666 |
description | A cell whose value can only be accessed by a owning thread |
homepage | |
repository | https://github.com/cehteh/threadcell.git |
max_upload_size | |
id | 654853 |
size | 32,566 |
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.
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.
There are two variants how Threadcells can be used. From 'v0.11' on these are mutually exclusive.
Offers manual control over a ThreadCell
ownership. The disadvantage here is that when a
thread holding a ThreadCell
will panic, this cell stays owned by the dead thread. One either
needs to discover these cases and then steal()
the cell or use that only in cases where
panics are impossible or aborting the whole process. This API can be used to implement custom
guard types as well.
threadcell::Guard
and threadcell::GuardMut
are handle proper acquire/release for
threadcells. There can be only one guard active per threadcell. As long a thread has a Guard
the threadcell is owned by that thread and will be released when the Guard
becomes dropped.
Guards implement Deref
and DerefMut
making accessing threadcells more ergonomic.
ThreadCell<RefCell<T>>
.static mut ThreadCell<T>
will needs unsafe code but is actually safe because
ThreadCell
guards against concurrent access.