liveBook · Manning

Chapter 1: Chapter 1. Hello, world of concurrency in C++!

What you will learn in chapter 1 of C++ Concurrency in Action, Second Edition

The chapter introduction explains why C++11’s standardized multithreading support mattered and previews the chapter’s path from basic concepts to a simple concurrent program.

After this chapter you will be able to

Section by section

Introduction

The chapter introduction explains why C++11’s standardized multithreading support mattered and previews the chapter’s path from basic concepts to a simple concurrent program.

Key terms: C++11, C++14, C++17, Technical Specifications, platform-specific extensions, portable multithreaded code, concurrency, multithreading, C++ concurrency support, simple example

1.1 What is concurrency?

The section introduces concurrency as two or more separate activities happening at the same time, using everyday examples.

Key terms: concurrency, separate activities

1.1.1 Concurrency in computer systems

This section distinguishes task-switched concurrency from genuine hardware concurrency and explains how hardware capacity affects execution and design.

Key terms: concurrency, task switching, hardware concurrency, context switch, CPU state, instruction pointer, cache, hardware threads, multicore processors

1.1.2 Approaches to concurrency

This section compares concurrency using separate processes with concurrency using threads in one process, then explains why the book focuses on threads.

Key terms: processes, interprocess communication, signals, sockets, files, pipes, threads, shared address space, shared memory, consistent

1.1.3 Concurrency vs. parallelism

This section distinguishes concurrency from parallelism by the goals people emphasize when using the terms, while stressing that their meanings overlap.

Key terms: concurrency, parallelism, separation of concerns, responsiveness, bulk data processing

1.2 Why use concurrency?

This section identifies separation of concerns and performance as the two main reasons to use concurrency.

Key terms: separation of concerns, performance

1.2.1 Using concurrency for separation of concerns

The section shows how assigning distinct responsibilities to threads can simplify code and keep an application responsive, even when increasing throughput is not the aim.

Key terms: separation of concerns, multithreading, user interface, DVD playback, responsiveness, busy cursor, Please Wait, background, number of threads, CPU cores

1.2.2 Using concurrency for performance: task and data parallelism

The section explains why multicore hardware makes concurrency important for performance and distinguishes reducing a task’s runtime from processing more data in the same time.

Key terms: multicore, parallel, concurrency, The free lunch is over, task parallelism, data parallelism, embarrassingly parallel, scalability, dependencies, throughput

1.2.3 When not to use concurrency

The section explains when the costs of concurrency outweigh its benefits, including development complexity, thread startup overhead, and the limits of running many threads.

Key terms: separation of concerns, multithreaded code, measurable gain, launching a thread, kernel resources, stack space, scheduler, spawning thread, limited resource, address space

1.3 Concurrency and multithreading in C++

Introduces C++11 as the point when C++ gained standardized multithreading support and explains why the library’s history matters.

Key terms: C++11 Standard, platform-specific extensions, Standard C++ Thread Library

1.3.1 History of multithreading in C++

This section explains how C++ programmers built multithreaded applications before standard thread support, and why the lack of a standard memory model remained a problem.

Key terms: 1998 C++ Standard, sequential abstract machine, memory model, compiler-specific extensions, platform-specific extensions, POSIX C, Microsoft Windows API, C++ Runtime Library, Boost, ACE

1.3.2 Concurrency support in the C++11 standard

The section introduces C++11’s standard concurrency support, its roots in Boost Thread, and the relevance of other C++11 language changes.

Key terms: thread-aware memory model, C++ Standard Library, threads, shared data, synchronizing operations, atomic operations, Boost Thread Library, C++11 Thread Library, C++11 Standard, Thread Library

1.3.3 More support for concurrency and parallelism in C++14 and C++17

This section contrasts the concurrency additions in C++14 and C++17, notes the Concurrency Technical Specification, and explains why C++ atomic operations support efficient, portable code.

Key terms: C++14, C++17, mutex type, parallel algorithms, Technical Specification for concurrency, synchronizing operations between threads, atomic operations, defined semantics, platform-specific assembly language, optimizer

1.3.4 Efficiency in the C++ Thread Library

This section explains the performance goals of the C++ Thread Library and when lower-level facilities may be worth using.

Key terms: abstraction penalty, C++ Standard Library, C++ Standard Thread Library, memory model, atomic operations library, atomic types, inter-thread synchronization, visibility, high-level abstractions, profiling

1.3.5 Platform-specific facilities

This section explains how C++ Thread Library types can provide access to platform-specific facilities, while recommending that readers learn the standard facilities first.

Key terms: C++ Thread Library, native_handle(), platform-specific API

1.4 Getting started

This section introduces the shape of a multithreaded C++ program and the two new concerns: managing threads and safely accessing shared data.

Key terms: functions, concurrently, threads, shared data, concurrent access

1.4.1 Hello, Concurrent World

The section turns a single-threaded Hello World program into a two-thread example, then explains why it must wait for the new thread and why this simple task gains little from concurrency.

Key terms: <thread>, std::thread, initial function, hello(), main(), join(), calling thread, multiple threads, initial thread

1.5 Summary

The chapter recap connects C++’s growing concurrency support with multicore hardware, then distinguishes the ease of starting threads from the difficulty of designing correct concurrent code.

Where this is used later

Concepts explained in this chapter

Chapter 2: Chapter 2. Managing threads →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.