Crate active_standby[−][src]
A concurrency primitive for high concurrency reads with a single writer.
While Readers will need to acquire a reader lock, they are guaranteed to never compete with the writer, meaning readers never face lock contention. This is achieved at the cost of:
- Memory - Internally we hold 2 copies of the underlying type the user is using. This allows us to have the active table, which is used by readers and the standby_table which is used by the writer.
- Writer thread CPU usage - The writer must apply all updates twice. Lock contention for the writer should be less than with a plain RwLock due to Readers using the active_table.
The usage is meant to be similar to a RwLock. Some of the inspiration came from the left_right crate, so feel free to check that out. We don't implement aliasing, so each table is a true deepcopy of the other. We also don't optimize for startup.
Structs
Reader | |
WriteGuard | WriteGuard is the way to mutate the underlying tables. A Writer can only generate 1 at a time, which is enforced by the borrow checker on creation. |
Writer | Writer is the class used to control the underlying tables. It is neither Send nor Sync. If you want multithreaded access to writing you must put it behind a lock. |
Type Definitions
RwLock | Define locally the lock types used incase we want to switch to a different implementation. |
RwLockReadGuard | |
RwLockWriteGuard |