{"id":19966834,"url":"https://github.com/rustcc/rust_atomics_and_locks","last_synced_at":"2025-10-24T02:31:38.964Z","repository":{"id":174862726,"uuid":"652573742","full_name":"rustcc/Rust_Atomics_and_Locks","owner":"rustcc","description":"Rust Atomics and Locks （中文翻译）","archived":false,"fork":false,"pushed_at":"2025-03-02T00:25:02.000Z","size":1225,"stargazers_count":282,"open_issues_count":5,"forks_count":37,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-04-19T13:12:59.806Z","etag":null,"topics":["rust","rust-lang","translation","zh-cn"],"latest_commit_sha":null,"homepage":"https://rustcc.github.io/Rust_Atomics_and_Locks/","language":"SCSS","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rustcc.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":"2023-06-12T10:53:33.000Z","updated_at":"2025-04-16T17:19:01.000Z","dependencies_parsed_at":"2023-07-22T19:01:10.118Z","dependency_job_id":"62116bbe-d11f-4672-9e3c-15928b4568e3","html_url":"https://github.com/rustcc/Rust_Atomics_and_Locks","commit_stats":null,"previous_names":["fwqaaq/rust_atomics_and_locks"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rustcc%2FRust_Atomics_and_Locks","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rustcc%2FRust_Atomics_and_Locks/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rustcc%2FRust_Atomics_and_Locks/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rustcc%2FRust_Atomics_and_Locks/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rustcc","download_url":"https://codeload.github.com/rustcc/Rust_Atomics_and_Locks/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254509476,"owners_count":22082891,"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":["rust","rust-lang","translation","zh-cn"],"created_at":"2024-11-13T02:38:44.576Z","updated_at":"2025-10-24T02:31:38.088Z","avatar_url":"https://github.com/rustcc.png","language":"SCSS","funding_links":[],"categories":[],"sub_categories":[],"readme":"## [第一章：Rust 并发基础](./1_Basic_of_Rust_Concurrency.md)\n\n* [Rust 中的线程](./1_Basic_of_Rust_Concurrency.md#rust-中的线程)\n* [作用域内的线程](./1_Basic_of_Rust_Concurrency.md#作用域内的线程)\n* [共享所有权以及引用计数](./1_Basic_of_Rust_Concurrency.md#共享所有权以及引用计数)\n  * [静态值（static）](./1_Basic_of_Rust_Concurrency.md#静态值static)\n  * [泄漏（Leak）](./1_Basic_of_Rust_Concurrency.md#泄漏leak)\n  * [引用计数](./1_Basic_of_Rust_Concurrency.md#引用计数)\n* [借用和数据竞争](./1_Basic_of_Rust_Concurrency.md#借用和数据竞争)\n* [内部可变性](./1_Basic_of_Rust_Concurrency.md#内部可变性)（[Cell](./1_Basic_of_Rust_Concurrency.md#cell)、[RefCell](./1_Basic_of_Rust_Concurrency.md#refcell)、[互斥锁以及读写锁](./1_Basic_of_Rust_Concurrency.md#互斥锁和读写锁)、[Atomic](./1_Basic_of_Rust_Concurrency.md#atomic)、[UnsafeCell](./1_Basic_of_Rust_Concurrency.md#unsafecell)）\n* [线程安全：Send 和 Sync](./1_Basic_of_Rust_Concurrency.md#线程安全send-和-sync)\n* [锁：互斥锁和读写锁](./1_Basic_of_Rust_Concurrency.md#锁互斥锁和读写锁)\n  * [Rust 的互斥锁](./1_Basic_of_Rust_Concurrency.md#rust-的互斥锁)\n  * [锁中毒](./1_Basic_of_Rust_Concurrency.md#锁中毒poison)\n  * [读写锁](./1_Basic_of_Rust_Concurrency.md#读写锁)\n* [等待：阻塞和条件变量](./1_Basic_of_Rust_Concurrency.md#等待-阻塞park和条件变量)\n  * [线程阻塞](./1_Basic_of_Rust_Concurrency.md#线程阻塞)\n  * [条件变量](./1_Basic_of_Rust_Concurrency.md#条件变量)\n* [总结](./1_Basic_of_Rust_Concurrency.md#总结)\n\n## [第二章：Atomic](./2_Atomics.md)\n\n* [Atomic 的加载和存储操作](./2_Atomics.md#atomic-的加载和存储操作)\n  * [示例：停止标识](./2_Atomics.md#示例停止标识)\n  * [示例：进度报道](./2_Atomics.md#示例进度报道)\n    * [同步](./2_Atomics.md#同步)\n  * [示例：惰性初始化](./2_Atomics.md#示例惰性初始化)\n* [获取并修改操作](./2_Atomics.md#获取并修改操作)\n  * [示例：来自多线程的进度报道](./2_Atomics.md#示例来自多线程的进度报道)\n  * [示例：统计数据](./2_Atomics.md#示例统计数据)\n  * [示例：ID 分配](./2_Atomics.md#示例id-分配)\n* [比较并交互操作](./2_Atomics.md#比较并交换操作)\n  * [示例：没有溢出的 ID 分配](./2_Atomics.md#示例没有溢出的-id-分配)\n  * [示例：惰性一次性初始化](./2_Atomics.md#示例惰性一次性初始化)\n* [总结](./2_Atomics.md#总结)\n\n## [第三章：内存排序](./3_Memory_Ordering.md)\n\n* [重排和优化](./3_Memory_Ordering.md#重排和优化)\n* [内存模型](./3_Memory_Ordering.md#内存模型)\n* [Happens-Before 关系](./3_Memory_Ordering.md#happens-before-关系)\n  * [spawn 和 join](./3_Memory_Ordering.md#spawn-和-join)\n* [Relaxed 排序](./3_Memory_Ordering.md#relaxed-排序)\n* [Release 和 Acquire 排序](./3_Memory_Ordering.md#release-和-acquire-排序)\n  * [示例：锁定](./3_Memory_Ordering.md#示例锁定)\n  * [示例：使用间接的方式惰性初始化](./3_Memory_Ordering.md#示例使用间接的方式惰性初始化)\n* [Consume 排序](./3_Memory_Ordering.md#consume-排序)\n* [顺序一致性排序](./3_Memory_Ordering.md#顺序一致性排序)\n* [屏障（Fence）](./3_Memory_Ordering.md#屏障fence2)\n* [常见的误解](./3_Memory_Ordering.md#常见的误解)\n* [总结](./3_Memory_Ordering.md#总结)\n\n## [第四章：构建我们自己的自旋锁](./4_Building_Our_Own_Spin_Lock.md)\n\n* [一个最小实现](./4_Building_Our_Own_Spin_Lock.md#一个最小实现)\n* [一个不安全的自旋锁](./4_Building_Our_Own_Spin_Lock.md#一个不安全的自旋锁)\n* [使用锁守卫的安全接口](./4_Building_Our_Own_Spin_Lock.md#使用锁守卫的安全接口)\n* [总结](./4_Building_Our_Own_Spin_Lock.md#总结)\n\n## [第五章：构建我们自己的 Channel](./5_Building_Our_Own_Channels.md)\n\n* [一个简单的以 mutex 为基础的 Channel](./5_Building_Our_Own_Channels.md#一个简单的以-mutex-为基础的-channel)\n* [一个不安全的一次性 Channel](./5_Building_Our_Own_Channels.md#一个不安全的一次性-channel)\n* [通过运行时检查来达到安全](./5_Building_Our_Own_Channels.md#通过运行时检查来达到安全)\n* [通过类型来达到安全](./5_Building_Our_Own_Channels.md#通过类型来达到安全)\n* [借用以避免内存分配](./5_Building_Our_Own_Channels.md#借用以避免内存分配)\n* [阻塞](./5_Building_Our_Own_Channels.md#阻塞)\n* [总结](./5_Building_Our_Own_Channels.md#总结)\n\n## [第六章：构建我们自己的“Arc”](./6_Building_Our_Own_Arc.md)\n\n* [基础的引用计数](./6_Building_Our_Own_Arc.md#基础的引用计数)\n  * [测试它](./6_Building_Our_Own_Arc.md#测试它)\n  * [可变性](./6_Building_Our_Own_Arc.md#可变性)\n* [Weak 指针](./6_Building_Our_Own_Arc.md#weak-指针)\n  * [测试它](./6_Building_Our_Own_Arc.md#测试它2)\n  * [优化](./6_Building_Our_Own_Arc.md#优化)\n* [总结](./6_Building_Our_Own_Arc.md#总结)\n\n## [第七章：理解处理器](./7_Understanding_the_Processor.md)\n\n* [处理器指令](./7_Understanding_the_Processor.md#处理器指令)\n  * [加载和存储操作](./7_Understanding_the_Processor.md#加载和存储操作)\n  * [读并修改并写操作](./7_Understanding_the_Processor.md#读并修改并写操作)\n    * [x86 lock 前缀](./7_Understanding_the_Processor.md#x86-lock-前缀)\n    * [x86 比较并交换指令](./7_Understanding_the_Processor.md#x86-比较并交换指令)\n  * [ll-和-sc-指令](./7_Understanding_the_Processor.md#ll-和-sc-指令)\n    * [arm-的-ldxr-和-stxr-指令](./7_Understanding_the_Processor.md#arm-的-ldxr-和-stxr-指令)\n    * [arm-的比较并交换操作](./7_Understanding_the_Processor.md#arm-的比较并交换操作)\n* [缓存](./7_Understanding_the_Processor.md#缓存3)\n  * [缓存一致性](./7_Understanding_the_Processor.md#缓存一致性)\n    * [write-through 协议](./7_Understanding_the_Processor.md#write-through-协议)\n    * [MESI 协议](./7_Understanding_the_Processor.md#mesi-协议4)\n  * [对性能的影响](./7_Understanding_the_Processor.md#对性能的影响)\n* [重排](./7_Understanding_the_Processor.md#重排)\n* [内存排序](./7_Understanding_the_Processor.md#内存排序)\n  * [x86-64：强排序](./7_Understanding_the_Processor.md#x86-64强排序)\n  * [ARM64：弱排序](./7_Understanding_the_Processor.md#arm64弱排序)\n  * [一个实验](./7_Understanding_the_Processor.md#一个实验)\n  * [内存屏障](./7_Understanding_the_Processor.md#内存屏障)\n* [总结](./7_Understanding_the_Processor.md#总结)\n\n## [第八章：操作系统原语](./8_Operating_System_Primitives.md)\n\n* [使用内核接口](./8_Operating_System_Primitives.md#使用内核接口)\n* [POSIX](./8_Operating_System_Primitives.md#posix)\n  * [在 Rust 中包装类型](./8_Operating_System_Primitives.md#在-rust-中包装类型)\n* [Linux](./8_Operating_System_Primitives.md#linux)\n  * [Futex](./8_Operating_System_Primitives.md#futex)\n  * [Futex 操作](./8_Operating_System_Primitives.md#futex-操作)\n  * [优先继承 Futex 操作](./8_Operating_System_Primitives.md#优先继承-futex-操作)\n* [macOS](./8_Operating_System_Primitives.md#macos)\n  * [os_unfair_lock](./8_Operating_System_Primitives.md#os_unfair_lock)\n* [Windows](./8_Operating_System_Primitives.md#windows)\n  * [重量级内核对象](./8_Operating_System_Primitives.md#重量级内核对象)\n  * [轻量级对象](./8_Operating_System_Primitives.md#轻量级对象)\n    * [精简的读写锁（SRW）](./8_Operating_System_Primitives.md#精简的读写srw锁5)\n  * [基于地址的等待](./8_Operating_System_Primitives.md#基于地址的等待)\n* [总结](./8_Operating_System_Primitives.md#总结)\n\n## [第九章：构建我们自己的「锁」](./9_Building_Our_Own_Locks.md)\n\n* [Mutex](./9_Building_Our_Own_Locks.md#mutex)\n  * [避免系统调用](./9_Building_Our_Own_Locks.md#避免系统调用)\n  * [进一步优化](./9_Building_Our_Own_Locks.md#进一步优化)\n  * [基准测试](./9_Building_Our_Own_Locks.md#基准测试)\n* [条件变量](./9_Building_Our_Own_Locks.md#条件变量)\n  * [避免系统调用2](./9_Building_Our_Own_Locks.md#避免系统调用2)\n  * [避免虚假唤醒](./9_Building_Our_Own_Locks.md#避免虚假唤醒)\n* [读写锁](./9_Building_Our_Own_Locks.md#读写锁)\n  * [避免 writer 忙碌循环](./9_Building_Our_Own_Locks.md#避免-writer-忙碌循环)\n  * [避免 writer 陷入饥饿](./9_Building_Our_Own_Locks.md#避免-writer-陷入饥饿)\n* [总结](./9_Building_Our_Own_Locks.md#总结)\n\n## [第十章：理念和灵感](./10_Ideas_and_Inspiration.md)\n\n* [信号量](./10_Ideas_and_Inspiration.md#信号)\n* [RCU](./10_Ideas_and_Inspiration.md#rcu)\n* [无锁链表](./10_Ideas_and_Inspiration.md#无锁链表)\n* [基于队列的锁](./10_Ideas_and_Inspiration.md#基于队列的锁)\n* [基于阻塞的锁](./10_Ideas_and_Inspiration.md#基于阻塞的锁)\n* [顺序锁](./10_Ideas_and_Inspiration.md#顺序锁sequence-lock)\n* [教学材料](./10_Ideas_and_Inspiration.md#教学材料)\n\n## [索引](./attachment.md)\n\n注明：本文译自 \u003chttps://marabos.nl/atomics/\u003e，若其它平台引用此翻译，也请注明出处。\n\n加入我们，编写[索引](https://github.com/rustcc/Rust_Atomics_and_Locks/blob/main/attachment.md#索引)或者进行[校对](https://github.com/rustcc/Rust_Atomics_and_Locks/issues/28)以帮助更多的人\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frustcc%2Frust_atomics_and_locks","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frustcc%2Frust_atomics_and_locks","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frustcc%2Frust_atomics_and_locks/lists"}