I will just give the analogy with which I understand memory consistency models (or memory models, for short). It is inspired by Leslie Lamport's seminal paper "Time, Clocks, and the Ordering of Events in a Distributed System". The analogy is apt…
http://www.amazon.com/Consistency-Coherence-Synthesis-Lectures-Architecture/dp/1608455645/ref=pd_sim_14_1?ie=UTF8&dpID=416Va%2B7GPIL&dpSrc=sims&preST=_AC_UL160_SR129%2C160_&refRID=0NSDDKF5MWV2FXY1QTVQ A Primer on Memory Consistency and Cac…
Linux has supported a large number of SMP systems based on a variety of CPUs since the 2.0 kernel. Linux has done an excellent job of abstracting away differences among these CPUs, even in kernel code. One important difference is how CPUs allow memor…
如果不使用任何同步机制(例如 mutex 或 atomic),在多线程中读写同一个变量,那么,程序的结果是难以预料的.简单来说,编译器以及 CPU 的一些行为,会影响到程序的执行结果: 即使是简单的语句,C++ 也不保证是原子操作. CPU 可能会调整指令的执行顺序. 在 CPU cache 的影响下,一个 CPU 执行了某个指令,不会立即被其它 CPU 看见. 利用 C++ 的 atomic<T> 能完成对象的原子的读.写以及RMW(read-modify-write),而参数 std::m…
并发框架分类 1. Executor相关类 Interfaces. Executor is a simple standardized interface for defining custom thread-like subsystems, including thread pools, asynchronous I/O, and lightweight task frameworks. Depending on which concrete Executor class is being u…