Prinzip: Orientierung an C++ 11/14, am Ende jeweils ein kurzes C#-Beispiel ergänzen, soweit verfügbar
Gliederung:
- Introduction
- Good reasons to use multi threading
- threading and objects are independent
- example for missing synchronization
racing condition
- Running multiple threads
- Simply starting a thread - std::thread
- Providing results - std::promise/future
- The simplest way for asynchronous execution - std::async
- Store tasks with explicit control for execution - std::packaged_task
- Synchronization - safe access to shared data
- Overview
potect only where necessary
- Understanding the problem of synchronization
(nicht mal auf bool kann sicher zugegriffen werden, compiler Optimierung kann zu geänderter Ausführungsreihenfolge führen)
- Mutexes and locks
- Basic functionality - std::lock_guard
- Repeatedly locking and unlocking - std::unique_lock
- Avoid long waiting for data access - std::recursive_timed_mutex
- Avoid deadlocks by locking several mutexes in one atomic step - std::lock
- Allgemeine Regeln (aus Lock keine Rufe nach aussen)
- Safe initialization of data
- std::call_once
- Static variables within a code block
- Atomics
- Using atomics the normal way - high level interface
- Using atomics the "relaxed" way - low-level interface only for experts
(nur ein kurzer Verweis)
- Wait and signal - std::condition_variable
- Basic functionality of condition variables - unsafe usage
- Using condition variables - the safe way
- Examples
- Waiting for one of two conditions
- WaitableCondition - simplified synchronization
TODO: C# ThreadId: not the same: int threadId = GetCurrentWin32ThreadId(); int managedThreadId = Thread.CurrentThread.ManagedThreadId;
compare
- promise/future in c++
- task in c#
racing condition and dead locks