Course Code: cpp14multith
Duration: 28 hours
Prerequisites:
  • Ability to use software development tools in C++ in a GNU/Linux and/or MS Windows environment
  • Knowledge of programming issues in C++ (procedural and object-oriented paradigm) at advanced and intermediate level
  • Knowledge of creating generalized code (templates)
Overview:

The training is intended for programmers who use the C++ language in their daily work at an advanced and intermediate level. The classes focus on presenting issues related to multi-threaded programming and building application architecture, starting from its structure and ending with technical aspects of production processes (testing, debugging). The course covers theoretical and practical issues, the knowledge of which allows you to estimate the performance of the future application and its stability. The scope of applications of multithreading design patterns and synchronization problems in classical patterns are also presented GoF. The C++14 language standard was adopted as the basic standard. However, the issues also cover newer language standards (up to C++2a). Additionally, issues related to cooperation with the GNU/Linux operating system and differences in the implementation of the standard library and the Boost library are also discussed.

Teaching resources used:

  • Lecture with a quiz to check your knowledge
  • Interactive exercises
  • Completing the assigned code
  • Easy code creation (from scratch)
  • Micro-project
Course Outline:

Concurrency challenges and problems

  • Platform hardware limitations - hardware threads, pipes, cache coherence
  • Elementary concepts related to multithreaded programming (multithreaded program correctness, lifetime, starvation, deadlock, race, atomicity, consistency models, Flynn's taxonomy)
  • Mechanisms for implementing multithreading and multiprocessing available in C++.
  • Standard library implementation - elements from C++14 to present (C++2a)
  • Implementation available in Boost - differences from the standard library

Processes and threads

  • Multiprocess and multithreaded applications
  • Operating system and threads (a brief overview of available implementations)
  • Process and thread synchronization mechanisms
  • Structural implementation of synchronization
  • Specificity of the implementation of multithreading in the object-oriented approach (role of the RAII pattern)

Memory model in language C++

  • Objects and places in memory
  • Scheduling operations and enforcing them
  • Relations: synchronization, priming, ordering of operations for atomic actions, release sequences
  • Memory barriers
  • Atomic operations

Thread management in standard C++14 and newer

  • The std::thread class and starting threads
  • Thread identification
  • Attaching and detaching a thread
  • Threads and standard containers
  • Exception handling in threads C++14

Mutual exclusion and critical sections

  • Simple rules of mutual exclusion
  • Concepts (types) of available locking objects
  • Quick introduction to time handling in C++14 (chrono library)
  • Classes std::mutex, std::timed_mutex, std::shared_mutex and derivatives
  • RAII pattern for lock handling (std::lock_guard, std::unique_lock)
  • Dependent and deferred locks (std::lock)
  • Ownership and co-ownership of locks and threads
  • The reader-writer problem
  • One-time initialization
  • Thread-local (private) memory (std::thread_local)

Locks and thread synchronization

  • Operations on semaphores
  • Recursive locks
  • Locks with lock level definition
  • Decision variables and interlock cooperation
  • Implementation of active and passive barriers (Idle Waits, Busy Waits)
  • Resuming threads
  • Communication between threads (Actor and CSP model)

Asynchronous tasks

  • Asynchronous events and their handling
  • Future
  • Promises (promises)
  • Prepared tasks (packaged_task)

Atomic types

  • Standard atomic types
  • Universal atomic flag (std::atomic_flag)
  • The std::atomic<T> class template and its specializations
  • Utility functions (free) of types std::atomic

Specifics of multi-threaded API design

  • Designing structures using interlocks - coarse and fine-grained interlocks
  • Concurrent code performance - estimation and measurement techniques
  • Data partitioning
  • Scalability of solutions
  • Handling errors and exceptional situations in the application architecture

Testing and debugging multi-threaded applications

  • Code reviews for multi-threaded operations
  • Specifics of testing multi-threaded applications
  • Unit tests
  • Increasing the probability of contingencies for testing
  • Formal methods for testing multithreaded applications
  • Multithreaded Application Architecture Patterns and Testing and Debugging (Overview)

Advanced thread management

  • Dependent threads (Saga pattern)
  • Avoiding competition in access to data
  • Controlled stopping and interruption of the thread
  • Interrupting blocking calls
  • Interrupt handling
  • Stealing tasks
  • Interrupting tasks when the application ends

Multithreading design patterns

  • Types and purpose of multithreaded patterns
  • Scope of application of patterns
  • Thread Pool
  • Active Object Pattern
  • Thread Safe Queue
  • Producer Consumer Pattern
  • Monitor pattern
  • Multithreaded security patterns GoF
Sites Published:

Polska - Programowanie wielowątkowe w języku C++