T1312

Ladda ner som PDF

C++ Threads Programming

Writing thread based programs is one of the most difficult programming tasks you can do. Actually, the general advice is to completely avoid putting in bugs in the code. If that advice turns out to be unrealistic, the next best thing you can do is program according to a set of well-known design patterns. In this course, we focus on the latter approach.

 This course has some concepts in common with the course “Threads Programming using C”, but uses C++ and C++11 to reach much farther into the land of concurrent programming.

Audience

C++ programmers that need to understand how to design and implement concurrent (aka thread based) applications.

Prior knowledge

Must be fluent in C++ programming.

Informator Training Cloud

Our training portal supports your development throughout the training. The portal saves you time and is designed to give you a more effective learning experience - leading to better results and greater knowledge enforcement after the course. Read more >

You Will Learn

  • Understand in depth the difference between threads and processes
  • Briefly about the new standard C++11
  • The POSIX Threads API and how to wrap it in C++
  • How to create and synchronize threads
  • The C++11 support for threads
  • Understand how to handle the classical concurrency problems such as critical sections, race conditions, deadlocks and starvation
  • How to create processes and how to create shared memory segments between processes

Platform

Ubuntu Linux 12.10 or later. GCC 4.7 (G++) compiler or later. A decent text editor, such as gedit, emacs, eclipse or similar.

Content:

The sections below show the course topics, but not necessarily organized into these chapters nor in the listed order.

Introduction to Threads and Processes

In this chapter we lay the groundwork for the course.

  • What is the difference between concurrent vs. parallel
  • What is thread and how is it related to a process
  • What is a task and what is an actor, and how are they related to threads and processes
  • The process virtual address space and its organization
  • The mechanics of a function call and why this is relevant to the understanding of a thread
  • A short overview of the evolution of concurrency operations

POSIX Threads

A first introduction to POSIX Threads (PThreads) and C++ threads .

  • Overview of the POSIX Threads API
  • Creating a simple thread
  • ... Läs mer

You Will Learn

  • Understand in depth the difference between threads and processes
  • Briefly about the new standard C++11
  • The POSIX Threads API and how to wrap it in C++
  • How to create and synchronize threads
  • The C++11 support for threads
  • Understand how to handle the classical concurrency problems such as critical sections, race conditions, deadlocks and starvation
  • How to create processes and how to create shared memory segments between processes

Platform

Ubuntu Linux 12.10 or later. GCC 4.7 (G++) compiler or later. A decent text editor, such as gedit, emacs, eclipse or similar.

Content:

The sections below show the course topics, but not necessarily organized into these chapters nor in the listed order.

Introduction to Threads and Processes

In this chapter we lay the groundwork for the course.

  • What is the difference between concurrent vs. parallel
  • What is thread and how is it related to a process
  • What is a task and what is an actor, and how are they related to threads and processes
  • The process virtual address space and its organization
  • The mechanics of a function call and why this is relevant to the understanding of a thread
  • A short overview of the evolution of concurrency operations

POSIX Threads

A first introduction to POSIX Threads (PThreads) and C++ threads .

  • Overview of the POSIX Threads API
  • Creating a simple thread
  • Initialization arguments of a thread
  • Configuration attributes of a threads, such as its stack size
  • Wrapping a thread in C++
  • C++11 threads and how to launch a new thread

The Critical Section Problem

Here we demonstrate the classic problem of critical sections and during which conditions it appear and how to avoid it.

  • The single bank account and multiple updaters problem
  • Understanding the problem and how to deal with it
  • POSIX mutex locks
  • Configuration attributes of mutex locks
  • Wrapping mutex locks in C++
  • C++11 mutex lock types
  • Recursive locks
  • Read/Write locks
  • Barriers

The Race-condition Problem

Here we demonstrate the classical problem of sending data between two threads.

  • The producer-consumer problem
  • Understanding the problem and how to deal with it
  • POSIX condition variables
  • Wrapping condition variables in C++
  • C++11 condition variables
  • C++11 unique locks and multi-locks
  • Configuration attributes of condition variables
  • The minimum amount of code to safely transfer a set of data items from one thread to another thread
  • A shared data class

Message passing

In this chapter we discuss the general concept of message passing as opposed to the paradigm of shared data, and compare the pros and cons of each approach.

  • What is message passing
  • The pros and cons of a message passing solution
  • The pros and cons of a shared data solution
  • Design and implementation of message queue
  • Bi-directional message passing
  • Rendezvous and futures/promises
  • The role of smart pointers in the context of threads programming
  • N clients and 1 server
  • 1 client and N servers

Deadlock and starvation

Here we discuss resource related problems such as starvation, livelock and deadlock.

  • What is a resource
  • Starvation and how to deal with it
  • Livelock and how to deal with it
  • Deadlock and how to understand it and how to prevent or detect it
  • What is actors concurrency and how differs it from threads concurrency
  • Using an Actors library
  • Towards the 100K concurrency problem

Actors

Semaphores

In this chapter we discuss the older (but sometimes important) concept of semaphores

  • What is semaphores
  • POSIX semaphores
  • Wrapping semaphores in C++
  • Memory-based semaphores
  • File-system based semaphores

Process creation

In this chapter we discuss process creation (fork/exec) and how to use semaphores to synchronize.

  • The mechanics of forking a new process
  • Understanding exit and wait
  • Zombies and daemons
  • How to lobotomize a process into a new process using exec
  • Basic synchronization of processes using semaphores

Shared memory

In this chapter we learn how to map a shared memory segment between two or more processes.

  • What is shared memory
  • Using the POSIX API for shared memory

Understanding the difference of synchronizing threads and processes and which POSIX data types can be of help in either case 

Kurs-ID: T1312
Längd: 3 dagar
Pris exkl moms: 26 950 kr

Frågor om kursen?

Har du frågor om kursens innehåll, leveransdatum/ort eller behöver en företagsanpassad variant? Fyll i formuläret nedan!


Kan betalas med:
TRAINING CARD

Ort och datum

Stockholm
16 jan-18 jan
Boka nu!
19 jun-21 jun
Boka nu!
Göteborg
16 jan-18 jan R
Boka nu!
19 jun-21 jun R
Boka nu!
Malmö
16 jan-18 jan R
Boka nu!
19 jun-21 jun R
Boka nu!
Cloud Access
i Läs mer

Delta på kursen från ditt hem, jobb eller annan plats.

16 jan-18 jan
Boka nu!
19 jun-21 jun
Boka nu!

Tipsa