orxfun / orx-split-vec

An efficient constant access time vector with dynamic capacity and pinned elements.
https://crates.io/crates/orx-split-vec
MIT License
2 stars 2 forks source link

support-for-concurrency #42

Closed orxfun closed 2 months ago

orxfun commented 2 months ago

Support for Concurrency

In version 2, PinnedVec grew with new methods to support concurrent data structures. However, this caused problems since these exposed methods were often unsafe, and further, they were not directly useful for the pinned vector consumers except for concurrent data structures wrapping a pinned vector. Furthermore, they are alien to a regular vector interface that we are used to using.

In version 3, a second trait called ConcurrentPinnedVec is defined. All useful methods related with concurrent programming are moved to this trait. This trait has an associated type defining the underlying pinned vector type. It can be turned into the pinned vector.

Finally, IntoConcurrentPinnedVec trait is defined. A pinned vector implementing this trait can be turned into a ConcurrentPinnedVec. As explained above, it can be converted back to the pinned vector.

This bi-directional transformation allows to wrap pinned vector to have concurrent support, and unwrap whenever concurrency is not required anymore.

An important advantage of this approach is that it allowed to clean up the PinnedVec api from unsafe and alien concurrency related methods.

Also

Tests using clock are revised so that currently pinned vector tests are miri safe.

PseudoDefault is required for all pinned vectors. Note that a FixedVec cannot implement a Default, but as any type, it can implement a pseudo-default, which is also required for concurrent wrappers.