Advanced Rust Library Design - from Double Buffers to a Concurrent HashMap
In this series we will implement a double buffer library, similar to left-right
but a lot more general.
Here is a preview of what is to come
- Humble Beginnings - see how double buffers are used, figure out use-cases, and implement a straight-forward single-threaded double-buffer
- A Fresh Start - use what we learned in Humble Beginnings to implement a better to use double buffer library
- Interlude on Unsafe - explore how unsafe interacts with various parts of Rust, what are safety contracts more
- Concurrent Updates Part 1 - adapt the single-threaded library to an naive consistent multi-threaded double buffer
- Interlude on Atomics - convert the naive double buffer to an eventually consistent multi-threaded double buffer
- Concurrent Updates Part 2 - convert the naive double buffer to an eventually consistent multi-threaded double buffer
- Generalizing Part 1 - generalize the library to handle custom pointers, and make it
no_std
compatible - Generalizing Part 2 - generalize the strategy used to synchronize the two buffers
- A Better Strategy - implement a better strategy designed by
Cassy343
inflashmap
- Async Compatibility - extend support to allow async buffer swaps
- Concurrent HashMap - implement a concurrent, eventually consistent, hashmap with a completely safe interface (including
retain
!) - Subtle Tricks - explore some tricks to regain some more power out of our double buffer library
At the end of each section, I will leave you with some questions. These will usually be covered in the next section, but it will be good for you to work them out yourself, cause that’s where you’ll learn.