During the three-day training, the first day I found that the lecturer was a C ++ cool: Herb Sutter. The company spent more than 2000 yuan on a single person, and I felt that it was not very worthwhile, it can be regarded as learned. It will be useful in the future:
Titled keep Itve concurrency Introduction and Overview
1. Three Pillars of dawn
- Concurrency for isolation: responsiveness
- Parallelism for Scalability: throughput, scalability
- Consistency by synchronization: race-Fess, deadlock-free
2. Concurrency fundamentals:
- A few good primitives: threads, pools, Lambdas, futures, locks and atomics
- Think in transactions: exception safety, public functions, and locked Blocks
- Habitually prefer structured/bounded lifetimes: locks, tasks, and more
- Recognize and avoid today's overheads: Switching, contention, the const of unrealized Parallelism
- Understand the ture nature of deadlock: locks + messages + I/O + any other blocking
- Concurrency is well solved on the server side, and is difficult to solve on the client side.
- The future trend of chips is mixed large & small cores multi-core systems.
3. Active Object Pattern
- Use active object to encapsulate all places that require Asynchronization or self-management of threads
- Active object can be used in Gui threads, decouple independent works, and encapsulate resources (I/O, shared objects)
- You need to implement an active helper
- You can use "Out" parameters or send a message back when you need to return values in the active object.
4. machine architecture, performance and scalability
- Root of all hardware complexity: latency (correctness + performance)
- Latency and bandwidth: bandwidth can be purchased with money. latency has limit
- The current bottleneck lies in memory rather than the CPU: int I = I1 + I2; double D = D1 * D2 requires the same cost, which is about 15 CPU circles. because 14 circles are spent on momory.
- Latency: registers, L1 cache, L2 cache, locak dram, remote dram, Flash, and disk
5. How to migrate code to the primary core "free lunch"
- Natural Parallelism: quicksort, trees, graphs, hash tables
- Benefits: faster on multiple cores, making full use of multiple cores
- Pay: races, deadlocks, cost vs sequential
- Basic parallel logic: fork-> Run-> join
- Understanding Scalability: the more cores the faster, the more things you need to consider (memory, I/O)
- Select appropriate data ures: you must consider both concurrency and parallconfiguration.
6. How to stop threads
A. Kill: thread. Abort (avoid, almost sertain to upload upt transactions)
B. Tell and don't take no for an answer: pthread_cancel (rudem only for ages without exceptions/unwind)
C. Ask: thead. Interrupt (better, but hard to use in practice)
D. Flag and let it poll (best, though requres cooperative effort)
7. Consistency: SAFT locking
- Prefer scoped locking and always have objects own locks
- Avoid races: associated data with locks
- Avoid deadlock: Apply lock hierarchies and other lock Ordering
- Aco id composability problems: Don't call unknow Code while holding a lock