Multithreading in C++

Course objectives

After completing this course you will be able to:

  • create, join and end threads
  • synchronize access to shared resources (mutexes, conditional variables, atomic variables, etc.)
  • catch and avoid bugs such as race condition, deadlock, etc.
  • create multithread-safe data structures (thread-safe queue) and use them to implement the Producer-Consumer pattern
  • implement Thread Pool and Active Object design patterns

Course syllabus

Introduction to multithreading

  • Threads and processes
  • Basics concepts of concurrency: program correctness, race-condition, mutual exclusion, liveness, starvation of threads, deadlock

Thread management

  • Classes: std::thread & std::jthread
  • Creating and running tasks in separate threads
  • Joining and detaching threads
  • Grouping threads – storing threads in standard containers
  • Hardware concurrency
  • Handling exceptions in threads - std::exception_ptr

Synchronizing threads - mutexes

  • Lockable concepts
  • Mutexes – implementation in standard library
    • std::mutex, std::timed_mutex and std::shared_mutex
    • Recursive mutexes
  • Lock managers – std::lock_guard<Mutex> and std::unique_lock<Mutex> classes
  • Synchronizing multithreaded code using mutexes
  • Avoiding deadlocks – using std::lock() function
  • Shared mutexes & locks – implementation of readers-writers pattern

Event synchronization

  • Communication mechanisms between threads
    • Busy waits – atomic flags
    • Idle waits – condition variables - std::condition_variable class
  • Thread-safe implementation of a queue
    • Producer-Consumer Design Pattern

Lazy initialization

• Thread-safe lazy initialization – Singleton and Virtual Proxy

Introduction to atomic types

  • std::atomic<T> class
  • Acquire-Release semantics
  • Memory model in C++11
  • Introduction to lock-free algorithms and data structures

Asynchronous functions

  • Asynchronous function calls – std::async()
  • Running asynchronous tasks – std::packaged_task class
  • Futures – results of asynchronous functions
  • std::promise - communication between threads

Design Patterns in multithreading

  • Thread Pool
  • Active Object

Prerequisites

Attendance of our Programming in C++ course or equivalent experience with C++

Course duration

3 days, 8 class hours each
On-site course quote

In-house training course.

Run at your company premises.

Get a quote
On-line course quote

In-house training course.

Delivered live in a virtual classroom.

Get a quote
Upcoming public courses
September 15 - 17, 2025 3490 PLN Enrol

Other dates?

Enquire now