This post is auto-generated from RSS feed
The Rust Programming Language Forum - Latest topics . Source:
AtomicVec: a fixed-capacity vector which allows concurrent reads and exclusive writes
Some days ago someone in this forum asked this:
I have an application where a global vector is growing as the program proceeds and once an element is created it does not change.
Adding elements to the vector is fast, but using an element of the vector may take a long time.
If I use an RwLock on the vector, the reads will block writes.
Is there a way to do the following:
Initialize the vector with a maximum size, set the elements to a default value that is not used, and set next_index to zero.
Have the writes store useful information at next_index, return next_index for use by future reads, and increment next_index.
Have the reads access elements below the current next_index, at the same time that a write stores information (as described in 2).
so I tried to implement this structure myself. It still isn't finished but the core functionalities are all there, so I'd be glad if someone could tell me their opinion about my code.
note that I didn't test it yet so maybe there's some unsoundness.
repository: GitHub - CieriA/atomicvec-rs: Rust library implementing fixed-capacity vector which allows concurrent reads and exclusive writes.
8 posts - 3 participants
Read full topic
🏷️ Rust_feed