{"id":15030490,"url":"https://github.com/downdemo/cpp-concurrency-in-action-2ed","last_synced_at":"2025-05-14T11:10:36.749Z","repository":{"id":37632699,"uuid":"211363244","full_name":"downdemo/Cpp-Concurrency-in-Action-2ed","owner":"downdemo","description":"C++11/14/17/20 multithreading, involving operating system principles and concurrent programming technology.","archived":false,"fork":false,"pushed_at":"2024-10-25T08:19:12.000Z","size":607,"stargazers_count":2019,"open_issues_count":1,"forks_count":337,"subscribers_count":23,"default_branch":"master","last_synced_at":"2024-10-29T17:56:14.931Z","etag":null,"topics":["multithreading","operating-systems"],"latest_commit_sha":null,"homepage":"https://downdemo.github.io/Cpp-Concurrency-in-Action-2ed/","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/downdemo.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":"2019-09-27T16:47:38.000Z","updated_at":"2024-10-28T13:27:26.000Z","dependencies_parsed_at":"2024-11-12T09:42:29.020Z","dependency_job_id":null,"html_url":"https://github.com/downdemo/Cpp-Concurrency-in-Action-2ed","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/downdemo%2FCpp-Concurrency-in-Action-2ed","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/downdemo%2FCpp-Concurrency-in-Action-2ed/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/downdemo%2FCpp-Concurrency-in-Action-2ed/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/downdemo%2FCpp-Concurrency-in-Action-2ed/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/downdemo","download_url":"https://codeload.github.com/downdemo/Cpp-Concurrency-in-Action-2ed/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248339794,"owners_count":21087321,"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":["multithreading","operating-systems"],"created_at":"2024-09-24T20:13:29.312Z","updated_at":"2025-04-11T04:19:45.706Z","avatar_url":"https://github.com/downdemo.png","language":"C++","readme":"* C++11 引入了 Boost 线程库作为标准线程库，作者 Anthony Williams 为介绍其特性，于 2012 年出版了 *[C++ Concurrency in Action](https://book.douban.com/subject/4130141/)* 一书，并顺应 C++17 于 2019 年 2 月出版了[第二版](https://book.douban.com/subject/27036085/)。*[C++ Concurrency in Action 2ed](https://learning.oreilly.com/library/view/c-concurrency-in/9781617294693/)* 前五章介绍了[线程支持库](https://en.cppreference.com/w/cpp/thread)的基本用法，后六章从实践角度介绍了并发编程的设计思想，相比第一版多介绍了一些 C++17 特性，如 [std::scoped_lock](https://en.cppreference.com/w/cpp/thread/scoped_lock)、[std::shared_mutex](https://en.cppreference.com/w/cpp/thread/shared_mutex)，并多出一章（第十章）介绍 [C++17 标准库并行算法](https://en.cppreference.com/w/cpp/header/execution)，此外个人会在相应处补充 C++20 相关特性，如 [std::jthread](https://en.cppreference.com/w/cpp/thread/jthread)、[std::counting_semaphore](https://en.cppreference.com/w/cpp/thread/counting_semaphore)、[std::barrier](https://en.cppreference.com/w/cpp/thread/barrier)、[std::latch](https://en.cppreference.com/w/cpp/thread/latch) 等。阅读本书前可参考 [Andrew S. Tanenbaum](https://en.wikipedia.org/wiki/Andrew_S._Tanenbaum) 的 [*Modern Operating Systems*](https://book.douban.com/subject/25864553/)，预备操作系统的基础知识（[进程与线程](https://github.com/downdemo/Cpp-Concurrency-in-Action-2ed/blob/master/docs/reference/processes_and_threads.md)、[死锁](https://github.com/downdemo/Cpp-Concurrency-in-Action-2ed/blob/master/docs/reference/deadlocks.md)、[内存管理](https://github.com/downdemo/Cpp-Concurrency-in-Action-2ed/blob/master/docs/reference/memory_management.md)、[文件系统](https://github.com/downdemo/Cpp-Concurrency-in-Action-2ed/blob/master/docs/reference/file_systems.md)、[I/O](https://github.com/downdemo/Cpp-Concurrency-in-Action-2ed/blob/master/docs/reference/IO.md) 等）。此为个人笔记，仅供参考，更详细内容见[原书](https://learning.oreilly.com/library/view/c-concurrency-in/9781617294693/)。\n\n## [线程支持库](https://en.cppreference.com/w/cpp/thread)\n\n1. [线程管理（Managing thread）](https://github.com/downdemo/Cpp-Concurrency-in-Action-2ed/blob/master/docs/01_managing_thread.md)：[\\\u003cthread\\\u003e](https://en.cppreference.com/w/cpp/header/thread)\n2. [线程间共享数据（Sharing data between thread）](https://github.com/downdemo/Cpp-Concurrency-in-Action-2ed/blob/master/docs/02_sharing_data_between_thread.md)：[\\\u003cmutex\\\u003e](https://en.cppreference.com/w/cpp/header/mutex)、[\\\u003cshared_mutex\\\u003e](https://en.cppreference.com/w/cpp/header/shared_mutex)\n3. [同步并发操作（Synchronizing concurrent operation）](https://github.com/downdemo/Cpp-Concurrency-in-Action-2ed/blob/master/docs/03_synchronizing_concurrent_operation.md)：[\\\u003ccondition_variable\\\u003e](https://en.cppreference.com/w/cpp/header/condition_variable)、[\\\u003csemaphore\\\u003e](https://en.cppreference.com/w/cpp/header/semaphore)、[\\\u003cbarrier\\\u003e](https://en.cppreference.com/w/cpp/header/barrier)、[\\\u003clatch\\\u003e](https://en.cppreference.com/w/cpp/header/latch)、[\\\u003cfuture\\\u003e](https://en.cppreference.com/w/cpp/header/future)、[\\\u003cchrono\\\u003e](https://en.cppreference.com/w/cpp/header/chrono)、[\\\u003cratio\\\u003e](https://en.cppreference.com/w/cpp/header/ratio)\n4. [C++ 内存模型和基于原子类型的操作（The C++ memory model and operations on atomic type）](https://github.com/downdemo/Cpp-Concurrency-in-Action-2ed/blob/master/docs/04_the_cpp_memory_model_and_operations_on_atomic_type.md)：[\\\u003catomic\\\u003e](https://en.cppreference.com/w/cpp/header/atomic)\n\n## 并发编程实践\n\n5. [基于锁的并发数据结构的设计（Designing lock-based concurrent data structure）](https://github.com/downdemo/Cpp-Concurrency-in-Action-2ed/blob/master/docs/05_designing_lock_based_concurrent_data_structure.md)\n6. [无锁并发数据结构的设计（Designing lock-free concurrent data structure）](https://github.com/downdemo/Cpp-Concurrency-in-Action-2ed/blob/master/docs/06_designing_lock_free_concurrent_data_structure.md)\n7. [并发代码的设计（Designing concurrent code）](https://github.com/downdemo/Cpp-Concurrency-in-Action-2ed/blob/master/docs/07_designing_concurrent_code.md)\n8. [高级线程管理（Advanced thread management）](https://github.com/downdemo/Cpp-Concurrency-in-Action-2ed/blob/master/docs/08_advanced_thread_management.md)\n9. [并行算法（Parallel algorithm）](https://github.com/downdemo/Cpp-Concurrency-in-Action-2ed/blob/master/docs/09_parallel_algorithm.md)：[\\\u003cexecution\\\u003e](https://en.cppreference.com/w/cpp/header/execution)\n10. [多线程应用的测试与调试（Testing and debugging multithreaded application）](https://github.com/downdemo/Cpp-Concurrency-in-Action-2ed/blob/master/docs/10_testing_and_debugging_multithreaded_application.md)\n\n## 标准库相关头文件\n\n|头文件|说明|\n|:-:|:-:|\n|[\\\u003cthread\\\u003e](https://en.cppreference.com/w/cpp/header/thread)、[\\\u003cstop_token\\\u003e](https://en.cppreference.com/w/cpp/header/stop_token)|线程|\n|[\\\u003cmutex\\\u003e](https://en.cppreference.com/w/cpp/header/mutex)、[\\\u003cshared_mutex\\\u003e](https://en.cppreference.com/w/cpp/header/shared_mutex)|锁|\n|[\\\u003ccondition_variable\\\u003e](https://en.cppreference.com/w/cpp/header/condition_variable)|条件变量|\n|[\\\u003csemaphore\\\u003e](https://en.cppreference.com/w/cpp/header/semaphore)|信号量|\n|[\\\u003cbarrier\\\u003e](https://en.cppreference.com/w/cpp/header/barrier)、[\\\u003clatch\\\u003e](https://en.cppreference.com/w/cpp/header/latch)|屏障|\n|[\\\u003cfuture\\\u003e](https://en.cppreference.com/w/cpp/header/future)|异步处理的结果|\n|[\\\u003cchrono\\\u003e](https://en.cppreference.com/w/cpp/header/chrono)|时钟|\n|[\\\u003cratio\\\u003e](https://en.cppreference.com/w/cpp/header/ratio)|编译期有理数算数|\n|[\\\u003catomic\\\u003e](https://en.cppreference.com/w/cpp/header/atomic)|原子类型和原子操作|\n|[\\\u003cexecution\\\u003e](https://en.cppreference.com/w/cpp/header/execution)|标准库算法执行策略|\n\n## 并发库对比\n\n### [C++11 Thread](https://en.cppreference.com/w/cpp/thread)\n\n|特性|API|\n|:-:|:-:|\n|thread|[std::thread](https://en.cppreference.com/w/cpp/thread/thread)|\n|mutex|[std::mutex](https://en.cppreference.com/w/cpp/thread/mutex)、[std::lock_guard](https://en.cppreference.com/w/cpp/thread/lock_guard)、[std::unique_lock](https://en.cppreference.com/w/cpp/thread/unique_lock)|\n|condition variable|[std::condition_variable](https://en.cppreference.com/w/cpp/thread/condition_variable)、[std::condition_variable_any](https://en.cppreference.com/w/cpp/thread/condition_variable_any)|\n|atomic|[std::atomic](https://en.cppreference.com/w/cpp/atomic/atomic)、[std::atomic_thread_fence](https://en.cppreference.com/w/cpp/atomic/atomic_thread_fence)|\n|future|[std::future](https://en.cppreference.com/w/cpp/thread/future)、[std::shared_future](https://en.cppreference.com/w/cpp/thread/shared_future)|\n|interruption|无|\n\n### [Boost Thread](https://www.boost.org/doc/libs/1_87_0/doc/html/thread.html)\n\n|特性|API|\n|:-:|:-:|\n|thread|[boost::thread](https://www.boost.org/doc/libs/1_87_0/doc/html/thread/thread_management.html#thread.thread_management.thread)|\n|mutex|[boost::mutex](https://www.boost.org/doc/libs/1_87_0/doc/html/thread/synchronization.html#thread.synchronization.mutex_types.mutex)、[boost::lock_guard](https://www.boost.org/doc/libs/1_87_0/doc/html/thread/synchronization.html#thread.synchronization.lock_guard.lock_guard)、[boost::unique_lock](https://www.boost.org/doc/libs/1_87_0/doc/html/thread/synchronization.html#thread.synchronization.locks.unique_lock)|\n|condition variable|[boost::condition_variable](https://www.boost.org/doc/libs/1_87_0/doc/html/thread/synchronization.html#thread.synchronization.condvar_ref.condition_variable)、[boost::condition_variable_any](https://www.boost.org/doc/libs/1_87_0/doc/html/thread/synchronization.html#thread.synchronization.condvar_ref.condition_variable_any)|\n|atomic|无|\n|future|[boost::future](https://www.boost.org/doc/libs/1_87_0/doc/html/thread/synchronization.html#thread.synchronization.futures.reference.unique_future)、[boost::shared_future](https://www.boost.org/doc/libs/1_87_0/doc/html/thread/synchronization.html#thread.synchronization.futures.reference.shared_future)|\n|interruption|[thread::interrupt](https://www.boost.org/doc/libs/1_87_0/doc/html/thread/thread_management.html#thread.thread_management.thread.interrupt)|\n\n### [POSIX Thread](http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/pthread.h.html)\n\n|特性|API|\n|:-:|:-:|\n|thread|[pthread_create](http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_create.html)、[pthread_detach](http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_detach.html#)、[pthread_join](http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_join.html#)|\n|mutex|[pthread_mutex_lock、pthread_mutex_unlock](http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_mutex_lock.html)|\n|condition variable|[pthread_cond_wait](http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_cond_wait.html)、[pthread_cond_signal](https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_cond_signal.html)|\n|atomic|无|\n|future|无|\n|interruption|[pthread_cancel](http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_cancel.html)|\n\n### [Java Thread](https://docs.oracle.com/en/java/javase/23/docs/api/java.base/java/lang/Thread.html)\n\n|特性|API|\n|:-:|:-:|\n|thread|[java.lang.Thread](https://docs.oracle.com/en/java/javase/23/docs/api/java.base/java/lang/Thread.html)|\n|mutex|[synchronized blocks](http://tutorials.jenkov.com/java-concurrency/synchronized.html)|\n|condition variable|[java.lang.Object.wait](https://docs.oracle.com/en/java/javase/23/docs/api/java.base/java/lang/Object.html#wait())、[java.lang.Object.notify](https://docs.oracle.com/en/java/javase/23/docs/api/java.base/java/lang/Object.html#notify())|\n|atomic|volatile 变量、[java.util.concurrent.atomic](https://docs.oracle.com/en/java/javase/23/docs/api/java.base/java/util/concurrent/atomic/package-summary.html)|\n|future|[java.util.concurrent.Future](https://docs.oracle.com/en/java/javase/23/docs/api/java.base/java/util/concurrent/Future.html)|\n|interruption|[java.lang.Thread.interrupt](https://docs.oracle.com/en/java/javase/23/docs/api/java.base/java/lang/Thread.html#interrupt())|\n|线程安全的容器|[java.util.concurrent](https://docs.oracle.com/en/java/javase/23/docs/api/java.base/java/util/concurrent/package-summary.html) 中的容器|\n|线程池|[java.util.concurrent.ThreadPoolExecutor](https://docs.oracle.com/en/java/javase/23/docs/api/java.base/java/util/concurrent/ThreadPoolExecutor.html)|\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdowndemo%2Fcpp-concurrency-in-action-2ed","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdowndemo%2Fcpp-concurrency-in-action-2ed","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdowndemo%2Fcpp-concurrency-in-action-2ed/lists"}