C++ 并发编程(七):读写锁(Read-Write Lock)

2016-09-19
阅读 2 分钟
59.1k
STL 和 Boost 都提供了 shared_mutex 来解决「读者-写者」问题。shared_mutex 这个名字并不十分贴切,不如 pthread 直呼「读写锁」。

C++ 并发编程(六):信号量(Semaphore)

2016-09-05
阅读 4 分钟
36.1k
Semaphore is a counter limiting the number of threads concurrently accessing a shared resource.This counter is always between 0 and the maximum value specified during the semaphore creation. When the counter is strictly greater than 0, a call to Wait returns immediately and decrements the counter...

C++ 并发编程(五):生产者 - 消费者

2016-08-24
阅读 3 分钟
24.9k
生产者 - 消费者(Producer-Consumer),也叫有限缓冲(Bounded-Buffer),是多线程同步的经典问题之一。详见 Wikipedia。

C++ 并发编程(四):基于 Asio 的线程池

2016-08-23
阅读 2 分钟
23.9k
目前项目中使用的线程池(详见:[链接]),虽然能用,但是代码复杂且很久没有人维护了。 本文结合 Thread 和 Asio,实现了一个线程池。一二十行代码,不能更简单了! 头文件: {代码...} 线程池类: {代码...} 成员变量 work_guard_ 的作用是,让 io_context 即使在没有异步任务可执行时也保持运行(即 io_context::run ...

C++ 并发编程(三):条件变量(Condition Variable)

2016-08-22
阅读 2 分钟
51.8k
条件变量(Condition Variable)的一般用法是:线程 A 等待某个条件并挂起,直到线程 B 设置了这个条件,并通知条件变量,然后线程 A 被唤醒。经典的「生产者-消费者」问题就可以用条件变量来解决。

C++ 并发编程(二):Mutex(互斥锁)

2016-08-17
阅读 3 分钟
41.6k
The mutex class is a synchronization primitive that can be used to protect shared data from being simultaneously accessed by multiple threads.

C++ 并发编程(一):创建线程

2016-08-10
阅读 3 分钟
17.9k
这个系列是我近期学习 C++ 并发编程的总结,文章和代码最初都是基于 Boost.Thread,但是最近越来越发现,STL 内置的线程和同步工具已经足够完善了。