Releases: orxfun/orx-concurrent-vec
2024edition
Upgrade PseudoDefault dependency
Merge pull request #43 from orxfun/Upgrade-PseudoDefault-dependency Upgrade PseudoDefault dependency
Dual license
Merge pull request #41 from orxfun/dual-license dual license
Use-of-Collection-constrained-PinnedVecs
Upgrade pinned vectors to v3.12.
Feature "serde"
- Serialize & Deserialize are implemented for ConcurrentVec. The concurrent vector is represented as a regular sequence.
- These implementations are available only through opt-in feature "serde".
- Example usage can be found in the corresponding test file.
Upgrade PinnedVec dependencies
- PinnedVec dependencies are upgraded to the latest.
- New clippy warnings are fixed.
Towards lock-free safe concurrent mutation
A major revision towards enabling safe concurrent grow & read & udpate methods.
Following are the notable changes.
ConcurrentElement
ConcurrentElement
struct is defined. A concurrent element is sort of an element which does not directly provide &T or &mut T references.
- Instead, it provides thread-safe methods such as
map
,cloned
,copied
to read the data. - And it provides thread-safe
update
,set
andreplace
methods to mutate the data.
Changes in the ConcurrentVec
Defining concurrent element api lead the changes in the entire crate:
vec.get(i)
orvec[i]
now returns&ConcurrentElement
. All thread safe access to the value is then provided by the concurrent element.- Similarly
vec.iter()
yields references to concurrent elements. - Since concurrent elements can both be read and mutated, methods such as
get_mut
oriter_mut
are not necessary.
ConcurrentSlice
ConcurrentSlice
is defined. This struct is analogous to a slice of a vec or slice.
- Slices provide safe and limited access to a certain region of the data. This feature is useful and convenient when we want to split the data to different threads.
- Slices have all read & update methods, and as expected, lack the grow methods.
Safety and Partially Unsafe Methods
Safety guarantees are re-evaluated. With the safe api of the concurrent vec, we must not have a race condition. At least, this is the claim and expectation reflecting the design decisions. Tests are in line with the claim so far.
Methods that provide direct &T
, &mut T
, *const T
or *mut T
accesses are kept; however, marked as unsafe
.
- Unsafe methods are now better defined.
- These methods are still partially safe due to the following:
- We cannot end up with a dangling pointer when using these methods.
- We cannot access out-of-bounds memory.
- We cannot access uninitialized or freed memory.
- The only undefined behavior we can experience is due to race conditions:
- The references returned by these methods leak out of the vector. Although they will remain valid, concurrent vector now has no means of preventing race conditions. Even when the user only reads through
&T
, we can still have race conditions since the concurrent vec itselfs allow thread-safe update methods.
- The references returned by these methods leak out of the vector. Although they will remain valid, concurrent vector now has no means of preventing race conditions. Even when the user only reads through
- Possible scenarios where the unsafe methods can be safely used are documented, demonstrated with examples and tested.
Crate is converted to no_std
Merge pull request #26 from orxfun/crate-turned-into-no_std crated turned into no_std
Clone, Index and IndexMut traits implemented
- Thread safe
Clone
method is implemented. Index
andIndexMut
traits are implemented forusize
indices.- Due to possibly fragmented nature of the underlying pinned vec, and since we cannot return a reference to a temporarily created collection, currently index over a range is not possible. This would be possible with
IndexMove
(see rust-lang/rfcs#997).
- Due to possibly fragmented nature of the underlying pinned vec, and since we cannot return a reference to a temporarily created collection, currently index over a range is not possible. This would be possible with
- Debug trait implementation is made mode convenient, revealing the current len and capacity in addition to the elements.
- Upgraded dependencies to pinned-vec (3.7) and pinned-concurrent-col (2.6) versions.
- Tests are extended:
- concurrent clone is tested.
- in addition to concurrent push & read, safety of concurrent extend & read is also tested.
- boxcar::Vec is added to the benchmarks.
32-bit support
Due to fix in the SplitVec https://github.com/orxfun/orx-split-vec/releases/tag/3.4.0