Threads Programming using Modern C++

How to build robust multi-threaded programs in C++, based on both POSIX Threads and the new standard C++ 11/14/17

Bugs in multi-threaded programs are often seen as the most troublesome issue one can get as a programmer. The general advise use to be to not put them there from the beginning.

If one think that advise is unrealistic, the next best is to code according to several well-proven programming-idioms which avoid the problems. In this course we focus on that strategi.

This course partly overlap with our course "POSIX & C11 Threads Programming using C", but differ in that it also encapsulate all C data-types in better C++ classes, and of course a thorough walk-through of threads in C++11/14/17.

This is what you will learn
  • Writing multi-threaded programs using POSIX Threads API
  • Writing multi-threaded programs in C++ based on class wrappers around the C Api
  • Writing multi-threaded programs in C++11
  • Understand and know how to deal with classical concurrency problems such as critical-sections, race-conditions and deadlocks
  • Using mutex locks and condition variables both in POSIX and C++11
  • Understand and know how to deal with promises/futures in C++1
Course Contents

Introduction to Threads and Concurrency

  • Concurrent vs. parallel
  • Scheduling
  • Synchronization
  • Virtual adress space organization
  • Overview of how a function-call is performed and why it's relevant to threads

POSIX Threads

  • Overview of the POSIX Threads C API
  • Creating a thread
  • Passing paramaters to a new thread
  • Configuring threads, like setting the stack-size
  • Implementing class Thread

The Critical Section Problem

  • Understanding the problem and its solution
  • Three conditions for the critical-section problem
  • POSIX mutex variables
  • Configuration
  • Handling timeouts
  • Avoiding self-deadlock
  • Implementing class Mutex
  • Implementing class Guard

The Race-Condition Problem

  • Understanding the problem and its solution
  • POSIX condition variables
  • Configuration
  • Handling timeouts
  • Understanding monitor semantics
  • The minimum amount of code to safely transfer data from one thread to another
  • Implementing class Condition
  • Implementing class MailBox

The Deadlock Problem

  • The concept resource
  • Understanding the problem and its solution
  • Four conditions for the deadlock problem
  • Preventing deadlocks
  • Detection of deadlocks

Synchronization and Other Data-Types

  • Read/Write locks
  • Barriers
  • Thread-local storage
  • Implementing classes for read/write locks
  • Implementing class Barrier
  • Implementing class ThreadLocalStorage

Semaphores

  • POSIX semaphores
  • Memory-based vs. file-based semaphores
  • Implementing class Semaphore
  • Implementing class FileSemaphore

Uni-directional Message Passing

  • What is message-passing
  • Handling pointer based messages
  • Understanding the message-queue concept and its synchronization requirements
  • Implementing class MessageQueue
  • Implementing class MessageThread
  • Implementing interface Receivable
  • Implementing a threads pipeline

Bi-directional Message Passing

  • N clients & 1 server
  • 1 client & N servers
  • Understanding Extended Rendezvous
  • Implementation of Extended Rendezvous
  • Understanding Futures
  • Implementation of Futures

Shared Memory

  • What is shared memory
  • Understanding the mmap() system call
  • The POSIX Shared Memory API
  • Implementing class SharedMemory

Threads & Processes

  • Creating processes
  • Waiting for process termination
  • Adapting mutexes and conditions for shared memory
  • Implementation of a message-queue in shared memory
  • Implementation of a threads pipeline between processes and via shared memory

A quick C++11/14/17 Primer

  • Highlights of the new standard relevant for the following chapters

Threads in C++11

  • Overview of the threads support first introduced in C++11
  • Using class thread
  • Usage of lambda expressions when defining threads

C++11 Synchronization

  • Using class mutex
  • Using class condition_variable
  • Usage of lock guards
  • Usage of multi-locking and avoidance of deadlocks
  • Implementation of class MessageQueue<T> using C++11

C++ Futures

  • Understanding C++11 promises & futures
  • Implementing Extended Rendezvous using C++11 futures
  • Spawning asynchronous tasks
Facts
NameThreads Programming using Modern C++
Duration3 Days
LevelAdvanced
AudienceExperienced C++ programmers
PrerequisitesKnowledge about Modern C++
Tools
  • GCC/G++ compiler, version 8 or later
  • Jetbrains CLion IDE
  • Ubuntu Linux @ VirtualBox or WLS @ Windows-10
Price19 000 kr + moms 19000
Course Dates
DatePlace
Loading course dates...
Same-Company Discout

We offer a 20% discount for additional participants from the same company and at the same course date. Read more here.

On-Site Course

If you order an On-Site course, we will come to you and hold the course in your office. The price is determined by our price model and is based on the number of course days, number of participants and any travel and lodging.

Read more about out price modell and term of sales here.

Related Courses
CourseDays Level
Linux Systems Programming using Modern C++3AdvancedShow
C++ Supplementary3Intermediate Show
C++ 11/14/17 for C++ Programmers3IntermediateShow
Basic course in Modern C++5BeginnerShow
Modern C++ for Java Developers4Beginner Show
POSIX Threads using C2 AdvancedShow