{"id":13539510,"url":"https://github.com/m-ou-se/rust-atomics-and-locks","last_synced_at":"2025-05-16T00:00:31.289Z","repository":{"id":65252843,"uuid":"578306533","full_name":"m-ou-se/rust-atomics-and-locks","owner":"m-ou-se","description":"Code examples, data structures, and links from my book, Rust Atomics and Locks.","archived":false,"fork":false,"pushed_at":"2024-08-06T02:28:39.000Z","size":37,"stargazers_count":1420,"open_issues_count":16,"forks_count":131,"subscribers_count":26,"default_branch":"main","last_synced_at":"2025-04-08T10:35:40.553Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/m-ou-se.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-12-14T18:36:02.000Z","updated_at":"2025-04-04T15:29:49.000Z","dependencies_parsed_at":"2024-01-14T07:04:10.623Z","dependency_job_id":"b07a7c48-7341-4328-979f-f11934d8195a","html_url":"https://github.com/m-ou-se/rust-atomics-and-locks","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/m-ou-se%2Frust-atomics-and-locks","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/m-ou-se%2Frust-atomics-and-locks/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/m-ou-se%2Frust-atomics-and-locks/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/m-ou-se%2Frust-atomics-and-locks/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/m-ou-se","download_url":"https://codeload.github.com/m-ou-se/rust-atomics-and-locks/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254442854,"owners_count":22071877,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T09:01:26.995Z","updated_at":"2025-05-16T00:00:31.094Z","avatar_url":"https://github.com/m-ou-se.png","language":"Rust","funding_links":[],"categories":["Rust","Programming languages"],"sub_categories":["Rust"],"readme":"This repository contains the code examples, data structures, and links from\n[Rust Atomics and Locks](https://marabos.nl/atomics/).\n\nThe examples from chapters 1, 2, 3, and 8 can be found in [examples/](examples/).\nThe data structures from chapters 4, 5, 6, and 9 can be found in [src/](src/).\n\n### Chapter 1 — Basics of Rust Concurrency\n\n- [examples/ch1-01-hello.rs](examples/ch1-01-hello.rs)\n- [examples/ch1-02-hello-join.rs](examples/ch1-02-hello-join.rs)\n- [examples/ch1-03-spawn-closure.rs](examples/ch1-03-spawn-closure.rs)\n- [examples/ch1-04-scoped-threads.rs](examples/ch1-04-scoped-threads.rs)\n- [examples/ch1-05-rc.rs](examples/ch1-05-rc.rs)\n- [examples/ch1-06-cell.rs](examples/ch1-06-cell.rs)\n- [examples/ch1-07-refcell.rs](examples/ch1-07-refcell.rs)\n- [examples/ch1-08-mutex.rs](examples/ch1-08-mutex.rs)\n- [examples/ch1-09-sleep-before-unlock.rs](examples/ch1-09-sleep-before-unlock.rs)\n- [examples/ch1-10-unlock-before-sleep.rs](examples/ch1-10-unlock-before-sleep.rs)\n- [examples/ch1-11-thread-parking.rs](examples/ch1-11-thread-parking.rs)\n- [examples/ch1-12-condvar.rs](examples/ch1-12-condvar.rs)\n\n### Chapter 2 — Atomics\n\n- [examples/ch2-01-stop-flag.rs](examples/ch2-01-stop-flag.rs)\n- [examples/ch2-02-progress-reporting.rs](examples/ch2-02-progress-reporting.rs)\n- [examples/ch2-03-progress-reporting-unpark.rs](examples/ch2-03-progress-reporting-unpark.rs)\n- [examples/ch2-04-lazy-init.rs](examples/ch2-04-lazy-init.rs)\n- [examples/ch2-05-fetch-add.rs](examples/ch2-05-fetch-add.rs)\n- [examples/ch2-06-progress-reporting-multiple-threads.rs](examples/ch2-06-progress-reporting-multiple-threads.rs)\n- [examples/ch2-07-statistics.rs](examples/ch2-07-statistics.rs)\n- [examples/ch2-08-id-allocation.rs](examples/ch2-08-id-allocation.rs)\n- [examples/ch2-09-id-allocation-panic.rs](examples/ch2-09-id-allocation-panic.rs)\n- [examples/ch2-10-id-allocation-subtract-before-panic.rs](examples/ch2-10-id-allocation-subtract-before-panic.rs)\n- [examples/ch2-11-increment-with-compare-exchange.rs](examples/ch2-11-increment-with-compare-exchange.rs)\n- [examples/ch2-12-id-allocation-without-overflow.rs](examples/ch2-12-id-allocation-without-overflow.rs)\n- [examples/ch2-13-lazy-one-time-init.rs](examples/ch2-13-lazy-one-time-init.rs)\n\n### Chapter 3 — Memory Ordering\n\n- [examples/ch3-01-relaxed.rs](examples/ch3-01-relaxed.rs)\n- [examples/ch3-02-spawn-join.rs](examples/ch3-02-spawn-join.rs)\n- [examples/ch3-03-total-modification-order.rs](examples/ch3-03-total-modification-order.rs)\n- [examples/ch3-04-total-modification-order-2.rs](examples/ch3-04-total-modification-order-2.rs)\n- [examples/ch3-05-out-of-thin-air.rs](examples/ch3-05-out-of-thin-air.rs)\n- [examples/ch3-06-release-acquire.rs](examples/ch3-06-release-acquire.rs)\n- [examples/ch3-07-release-acquire-unsafe.rs](examples/ch3-07-release-acquire-unsafe.rs)\n- [examples/ch3-08-lock.rs](examples/ch3-08-lock.rs)\n- [examples/ch3-09-lazy-init-box.rs](examples/ch3-09-lazy-init-box.rs)\n- [examples/ch3-10-seqcst.rs](examples/ch3-10-seqcst.rs)\n- [examples/ch3-11-fence.rs](examples/ch3-11-fence.rs)\n\n### Chapter 4 — Building Our Own Spin Lock\n\n- [src/ch4_spin_lock/s1_minimal.rs](src/ch4_spin_lock/s1_minimal.rs)\n- [src/ch4_spin_lock/s2_unsafe.rs](src/ch4_spin_lock/s2_unsafe.rs)\n- [src/ch4_spin_lock/s3_guard.rs](src/ch4_spin_lock/s3_guard.rs)\n\n### Chapter 5 — Building Our Own Channels\n\n- [src/ch5_channels/s1_simple.rs](src/ch5_channels/s1_simple.rs)\n- [src/ch5_channels/s2_unsafe.rs](src/ch5_channels/s2_unsafe.rs)\n- [src/ch5_channels/s3_checks.rs](src/ch5_channels/s3_checks.rs)\n- [src/ch5_channels/s3_single_atomic.rs](src/ch5_channels/s3_single_atomic.rs)\n- [src/ch5_channels/s4_types.rs](src/ch5_channels/s4_types.rs)\n- [src/ch5_channels/s5_borrowing.rs](src/ch5_channels/s5_borrowing.rs)\n- [src/ch5_channels/s6_blocking.rs](src/ch5_channels/s6_blocking.rs)\n\n### Chapter 6 — Building Our Own “Arc”\n\n- [src/ch6_arc/s1_basic.rs](src/ch6_arc/s1_basic.rs)\n- [src/ch6_arc/s2_weak.rs](src/ch6_arc/s2_weak.rs)\n- [src/ch6_arc/s3_optimized.rs](src/ch6_arc/s3_optimized.rs)\n\n### Chapter 7 — Understanding the Processor\n\n- https://godbolt.org/\n\n### Chapter 8 — Operating System Primitives\n\n- [examples/ch8-01-futex.rs](examples/ch8-01-futex.rs)\n\n### Chapter 9 — Building Our Own Locks\n\n- [src/ch9_locks/mutex_1.rs](src/ch9_locks/mutex_1.rs)\n- [src/ch9_locks/mutex_2.rs](src/ch9_locks/mutex_2.rs)\n- [src/ch9_locks/mutex_3.rs](src/ch9_locks/mutex_3.rs)\n- [src/ch9_locks/condvar_1.rs](src/ch9_locks/condvar_1.rs)\n- [src/ch9_locks/condvar_2.rs](src/ch9_locks/condvar_2.rs)\n- [src/ch9_locks/rwlock_1.rs](src/ch9_locks/rwlock_1.rs)\n- [src/ch9_locks/rwlock_2.rs](src/ch9_locks/rwlock_2.rs)\n- [src/ch9_locks/rwlock_3.rs](src/ch9_locks/rwlock_3.rs)\n\n### Chapter 10 — Ideas and Inspiration\n\n- [Wikipedia article on semaphores](https://en.wikipedia.org/wiki/Semaphore_(programming))\n- [Stanford University course notes on semaphores](https://see.stanford.edu/materials/icsppcs107/23-Concurrency-Examples.pdf)\n- [Wikipedia article on the read-copy-update pattern](https://en.wikipedia.org/wiki/Read-copy-update)\n- [LWN article \"What is RCU, Fundamentally?\"](https://lwn.net/Articles/262464/)\n- [Wikipedia article on non-blocking linked lists](https://en.wikipedia.org/wiki/Non-blocking_linked_list)\n- [LWN article \"Using RCU for Linked Lists—A Case Study\"](https://lwn.net/Articles/610972/)\n- [Notes on the implementation of Windows SRW locks](https://github.com/rust-lang/rust/issues/93740#issuecomment-1064139337)\n- [A Rust implementation of queue-based locks](https://github.com/kprotty/usync)\n- [WebKit blog post, \"Locking in WebKit\"](https://webkit.org/blog/6161/locking-in-webkit/)\n- [Documentation of the `parking_lot` crate](https://docs.rs/parking_lot)\n- [Wikipedia article on Linux's Seqlock](https://en.wikipedia.org/wiki/Seqlock)\n- [Rust RFC 3301, `AtomicPerByte`](https://rust.tf/rfc3301)\n- [Documentation of the `seqlock` crate](https://docs.rs/seqlock)\n\n### License\n\nYou may use all code in this repository for any purpose.\n\nAttribution is appreciated, but not required.\nAn attribution usually includes the book title, author, publisher, and ISBN.\nFor example: \"_Rust Atomics and Locks_ by Mara Bos (O’Reilly). Copyright 2023 Mara Bos, 978-1-098-11944-7.\"\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fm-ou-se%2Frust-atomics-and-locks","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fm-ou-se%2Frust-atomics-and-locks","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fm-ou-se%2Frust-atomics-and-locks/lists"}