This repository contains the code examples, data structures, and links from
[Rust Atomics and Locks](https://marabos.nl/atomics/).
The examples from chapters 1, 2, 3, and 8 can be found in [examples/](examples/).
The data structures from chapters 4, 5, 6, and 9 can be found in [src/](src/).
### Chapter 1 — Basics of Rust Concurrency
- [examples/ch1-01-hello.rs](examples/ch1-01-hello.rs)
- [examples/ch1-02-hello-join.rs](examples/ch1-02-hello-join.rs)
- [examples/ch1-03-spawn-closure.rs](examples/ch1-03-spawn-closure.rs)
- [examples/ch1-04-scoped-threads.rs](examples/ch1-04-scoped-threads.rs)
- [examples/ch1-05-rc.rs](examples/ch1-05-rc.rs)
- [examples/ch1-06-cell.rs](examples/ch1-06-cell.rs)
- [examples/ch1-07-refcell.rs](examples/ch1-07-refcell.rs)
- [examples/ch1-08-mutex.rs](examples/ch1-08-mutex.rs)
- [examples/ch1-09-sleep-before-unlock.rs](examples/ch1-09-sleep-before-unlock.rs)
- [examples/ch1-10-unlock-before-sleep.rs](examples/ch1-10-unlock-before-sleep.rs)
- [examples/ch1-11-thread-parking.rs](examples/ch1-11-thread-parking.rs)
- [examples/ch1-12-condvar.rs](examples/ch1-12-condvar.rs)
### Chapter 2 — Atomics
- [examples/ch2-01-stop-flag.rs](examples/ch2-01-stop-flag.rs)
- [examples/ch2-02-progress-reporting.rs](examples/ch2-02-progress-reporting.rs)
- [examples/ch2-03-progress-reporting-unpark.rs](examples/ch2-03-progress-reporting-unpark.rs)
- [examples/ch2-04-lazy-init.rs](examples/ch2-04-lazy-init.rs)
- [examples/ch2-05-fetch-add.rs](examples/ch2-05-fetch-add.rs)
- [examples/ch2-06-progress-reporting-multiple-threads.rs](examples/ch2-06-progress-reporting-multiple-threads.rs)
- [examples/ch2-07-statistics.rs](examples/ch2-07-statistics.rs)
- [examples/ch2-08-id-allocation.rs](examples/ch2-08-id-allocation.rs)
- [examples/ch2-09-id-allocation-panic.rs](examples/ch2-09-id-allocation-panic.rs)
- [examples/ch2-10-id-allocation-subtract-before-panic.rs](examples/ch2-10-id-allocation-subtract-before-panic.rs)
- [examples/ch2-11-increment-with-compare-exchange.rs](examples/ch2-11-increment-with-compare-exchange.rs)
- [examples/ch2-12-id-allocation-without-overflow.rs](examples/ch2-12-id-allocation-without-overflow.rs)
- [examples/ch2-13-lazy-one-time-init.rs](examples/ch2-13-lazy-one-time-init.rs)
### Chapter 3 — Memory Ordering
- [examples/ch3-01-relaxed.rs](examples/ch3-01-relaxed.rs)
- [examples/ch3-02-spawn-join.rs](examples/ch3-02-spawn-join.rs)
- [examples/ch3-03-total-modification-order.rs](examples/ch3-03-total-modification-order.rs)
- [examples/ch3-04-total-modification-order-2.rs](examples/ch3-04-total-modification-order-2.rs)
- [examples/ch3-05-out-of-thin-air.rs](examples/ch3-05-out-of-thin-air.rs)
- [examples/ch3-06-release-acquire.rs](examples/ch3-06-release-acquire.rs)
- [examples/ch3-07-release-acquire-unsafe.rs](examples/ch3-07-release-acquire-unsafe.rs)
- [examples/ch3-08-lock.rs](examples/ch3-08-lock.rs)
- [examples/ch3-09-lazy-init-box.rs](examples/ch3-09-lazy-init-box.rs)
- [examples/ch3-10-seqcst.rs](examples/ch3-10-seqcst.rs)
- [examples/ch3-11-fence.rs](examples/ch3-11-fence.rs)
### Chapter 4 — Building Our Own Spin Lock
- [src/ch4_spin_lock/s1_minimal.rs](src/ch4_spin_lock/s1_minimal.rs)
- [src/ch4_spin_lock/s2_unsafe.rs](src/ch4_spin_lock/s2_unsafe.rs)
- [src/ch4_spin_lock/s3_guard.rs](src/ch4_spin_lock/s3_guard.rs)
### Chapter 5 — Building Our Own Channels
- [src/ch5_channels/s1_simple.rs](src/ch5_channels/s1_simple.rs)
- [src/ch5_channels/s2_unsafe.rs](src/ch5_channels/s2_unsafe.rs)
- [src/ch5_channels/s3_checks.rs](src/ch5_channels/s3_checks.rs)
- [src/ch5_channels/s3_single_atomic.rs](src/ch5_channels/s3_single_atomic.rs)
- [src/ch5_channels/s4_types.rs](src/ch5_channels/s4_types.rs)
- [src/ch5_channels/s5_borrowing.rs](src/ch5_channels/s5_borrowing.rs)
- [src/ch5_channels/s6_blocking.rs](src/ch5_channels/s6_blocking.rs)
### Chapter 6 — Building Our Own “Arc”
- [src/ch6_arc/s1_basic.rs](src/ch6_arc/s1_basic.rs)
- [src/ch6_arc/s2_weak.rs](src/ch6_arc/s2_weak.rs)
- [src/ch6_arc/s3_optimized.rs](src/ch6_arc/s3_optimized.rs)
### Chapter 7 — Understanding the Processor
- https://godbolt.org/
### Chapter 8 — Operating System Primitives
- [examples/ch8-01-futex.rs](examples/ch8-01-futex.rs)
### Chapter 9 — Building Our Own Locks
- [src/ch9_locks/mutex_1.rs](src/ch9_locks/mutex_1.rs)
- [src/ch9_locks/mutex_2.rs](src/ch9_locks/mutex_2.rs)
- [src/ch9_locks/mutex_3.rs](src/ch9_locks/mutex_3.rs)
- [src/ch9_locks/condvar_1.rs](src/ch9_locks/condvar_1.rs)
- [src/ch9_locks/condvar_2.rs](src/ch9_locks/condvar_2.rs)
- [src/ch9_locks/rwlock_1.rs](src/ch9_locks/rwlock_1.rs)
- [src/ch9_locks/rwlock_2.rs](src/ch9_locks/rwlock_2.rs)
- [src/ch9_locks/rwlock_3.rs](src/ch9_locks/rwlock_3.rs)
### Chapter 10 — Ideas and Inspiration
- [Wikipedia article on semaphores](https://en.wikipedia.org/wiki/Semaphore_(programming))
- [Stanford University course notes on semaphores](https://see.stanford.edu/materials/icsppcs107/23-Concurrency-Examples.pdf)
- [Wikipedia article on the read-copy-update pattern](https://en.wikipedia.org/wiki/Read-copy-update)
- [LWN article "What is RCU, Fundamentally?"](https://lwn.net/Articles/262464/)
- [Wikipedia article on non-blocking linked lists](https://en.wikipedia.org/wiki/Non-blocking_linked_list)
- [LWN article "Using RCU for Linked Lists—A Case Study"](https://lwn.net/Articles/610972/)
- [Notes on the implementation of Windows SRW locks](https://github.com/rust-lang/rust/issues/93740#issuecomment-1064139337)
- [A Rust implementation of queue-based locks](https://github.com/kprotty/usync)
- [WebKit blog post, "Locking in WebKit"](https://webkit.org/blog/6161/locking-in-webkit/)
- [Documentation of the `parking_lot` crate](https://docs.rs/parking_lot)
- [Wikipedia article on Linux's Seqlock](https://en.wikipedia.org/wiki/Seqlock)
- [Rust RFC 3301, `AtomicPerByte`](https://rust.tf/rfc3301)
- [Documentation of the `seqlock` crate](https://docs.rs/seqlock)
### 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."
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
该GitHub仓库(main分支下的“示例”文件夹)是由Rust核心贡献者Mara Bos维护的开源项目,专注于提供Rust中的并发编程资源。通过一系列可运行的代码示例,它帮助开发者掌握原子操作(如AtomicUsize)和锁机制(如Mutex、RwLock),实现高效、线程安全的程序。内容覆盖基础到高级主题,包括内存顺序、死锁避免等,旨在降低学习曲线并提升实际应用能力。仓库作为教育工具,适用于系统编程、高性能计算等场景。这个仓库是学习Rust并发的宝贵工具,通过实践驱动的示例降低了学习曲线。此仓库是Rust生态的重要组成部分,因为它填补了官方文档的空白,通过亲手实践提升开发者的技能。为什么重要?在现代多核处理器环境下,有效使用原子操作和锁能显著提升程序性能和可靠性。
资源推荐
资源详情
资源评论






























收起资源包目录

















































































共 71 条
- 1
资源评论


weixin_pk138132
- 粉丝: 406
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助


最新资源
- Laravel5微信小程序登录获取用户信息扩展.zip
- D时间无关薛定谔方程求解器_3D Time independent Schroedinger equation solv
- 抖音电商,分行业topX商品基础数据+销量数据,提供小程序和api查询.zip
- Schlecht,S.,Alary,B.,V lim ki,V.,Habets,E.的Matlab代码()。优化天鹅绒噪
- 软件_matlab.zip
- 微信小程序AR测试.zip
- 佛罗里达州富尔尔。MW风力发电机组数据集预处理函数R MATLAB_Fuhrländer FL2500 2.5MW wi
- 使用MATLAB引擎的语言服务器_Language Server using MATLAB Engine.zip
- MATLAB实现直方图均衡_Histogram Equalization Implementation by MATLA
- 数字图像水印使用matlab(DWT、DCT),GUI使用python_Digital Image Watermarki
- 该MATLAB项目可以对Agilent_E A LCR仪表进行数据监测和记录。_This MATLAB project
- 微信小程序 Sports News(体育新闻).zip
- MATLAB的TOML实现_TOML implementation for MATLAB.zip
- wechat mini program swipe card component(微信小程序卡片滑动组件).zip
- 微信小程序自定义样式轮播图,阴影、动画缩放、中间大两边小.zip
- 使用zbar扫描,zxing生成和读取本地二维码图片.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈



安全验证
文档复制为VIP权益,开通VIP直接复制
