Debian Codegraph @

debian/rust-vendor/bitvec/doc/slice/threadsafe.md

raw
1 # Bit-Slice Thread Safety
2
3 This allows bit-slice references to be moved across thread boundaries only when
4 the underlying `T` element can tolerate concurrency.
5
6 All `BitSlice` references, shared or exclusive, are only threadsafe if the `T`
7 element type is `Send`, because any given bit-slice reference may only have
8 partial control of a memory element that is also being shared by a bit-slice
9 reference on another thread. As such, this is never implemented for `Cell<U>`,
10 but always implemented for `AtomicU` and `U` for a given unsigned integer type
11 `U`.
12
13 Atomic integers safely handle concurrent writes, cells do not allow concurrency
14 at all, so the only missing piece is `&mut BitSlice<_, U: Unsigned>`. This is
15 handled by the aliasing system that the mutable splitters employ: a mutable
16 reference to an unsynchronized bit-slice can only cross threads when no other
17 handle is able to exist to the elements it governs. Splitting a mutable
18 bit-slice causes the split halves to change over to either atomics or cells, so
19 concurrency is either safe or impossible.