This repository contains the code examples, data structures, and links from Rust Atomics and Locks.
The examples from chapters 1, 2, 3, and 8 can be found in examples/. The data structures from chapters 4, 5, 6, and 9 can be found in src/.
Chapter 1 โ Basics of Rust Concurrency
- examples/ch1-01-hello.rs
- examples/ch1-02-hello-join.rs
- examples/ch1-03-spawn-closure.rs
- examples/ch1-04-scoped-threads.rs
- examples/ch1-05-rc.rs
- examples/ch1-06-cell.rs
- examples/ch1-07-refcell.rs
- examples/ch1-08-mutex.rs
- examples/ch1-09-sleep-before-unlock.rs
- examples/ch1-10-unlock-before-sleep.rs
- examples/ch1-11-thread-parking.rs
- examples/ch1-12-condvar.rs
Chapter 2 โ Atomics
- examples/ch2-01-stop-flag.rs
- examples/ch2-02-progress-reporting.rs
- examples/ch2-03-progress-reporting-unpark.rs
- examples/ch2-04-lazy-init.rs
- examples/ch2-05-fetch-add.rs
- examples/ch2-06-progress-reporting-multiple-threads.rs
- examples/ch2-07-statistics.rs
- examples/ch2-08-id-allocation.rs
- examples/ch2-09-id-allocation-panic.rs
- examples/ch2-10-id-allocation-subtract-before-panic.rs
- examples/ch2-11-increment-with-compare-exchange.rs
- examples/ch2-12-id-allocation-without-overflow.rs
- examples/ch2-13-lazy-one-time-init.rs
Chapter 3 โ Memory Ordering
- examples/ch3-01-relaxed.rs
- examples/ch3-02-spawn-join.rs
- examples/ch3-03-total-modification-order.rs
- examples/ch3-04-total-modification-order-2.rs
- examples/ch3-05-out-of-thin-air.rs
- examples/ch3-06-release-acquire.rs
- examples/ch3-07-release-acquire-unsafe.rs
- examples/ch3-08-lock.rs
- examples/ch3-09-lazy-init-box.rs
- examples/ch3-10-seqcst.rs
- examples/ch3-11-fence.rs
Chapter 4 โ Building Our Own Spin Lock
Chapter 5 โ Building Our Own Channels
- src/ch5_channels/s1_simple.rs
- src/ch5_channels/s2_unsafe.rs
- src/ch5_channels/s3_checks.rs
- src/ch5_channels/s3_single_atomic.rs
- src/ch5_channels/s4_types.rs
- src/ch5_channels/s5_borrowing.rs
- src/ch5_channels/s6_blocking.rs
Chapter 6 โ Building Our Own โArcโ
Chapter 7 โ Understanding the Processor
Chapter 8 โ Operating System Primitives
Chapter 9 โ Building Our Own Locks
- src/ch9_locks/mutex_1.rs
- src/ch9_locks/mutex_2.rs
- src/ch9_locks/mutex_3.rs
- src/ch9_locks/condvar_1.rs
- src/ch9_locks/condvar_2.rs
- src/ch9_locks/rwlock_1.rs
- src/ch9_locks/rwlock_2.rs
- src/ch9_locks/rwlock_3.rs
Chapter 10 โ Ideas and Inspiration
- Wikipedia article on semaphores
- Stanford University course notes on semaphores
- Wikipedia article on the read-copy-update pattern
- LWN article "What is RCU, Fundamentally?"
- Wikipedia article on non-blocking linked lists
- LWN article "Using RCU for Linked ListsโA Case Study"
- Notes on the implementation of Windows SRW locks
- A Rust implementation of queue-based locks
- WebKit blog post, "Locking in WebKit"
- Documentation of the
parking_lot
crate - Wikipedia article on Linux's Seqlock
- Rust RFC 3301,
AtomicPerByte
- Documentation of the
seqlock
crate
License
You may use all code in this repository for any purpose.
Attribution is appreciated, but not required. An attribution usually includes the book title, author, publisher, and ISBN. For example: "Rust Atomics and Locks by Mara Bos (OโReilly). Copyright 2023 Mara Bos, 978-1-098-11944-7."