We will analyse such code
#include
#include
using namespace std;
int main() {
atomic stop{false};
auto f = [&] {
while (not stop) {
/* do sth... */
}
};
thread t(f);
stop = true;
t.join();
return 0;
}
#include
using namespace std;
int main() {
volatile bool stop = false;
auto f = [&] {
while (not stop) {
/* do sth... */
}
};
thread t(f);
stop = true;
t.join();
return 0;
}
Your abilities after Multithreading – atomic, condition_variable, call_once
training
- know when synchronization is needed and what it is not
- use atomics for lightweight synchronization
- are aware of sequential consistency and the order of operations on memory
-
use
call_once
andonce_flag
-
know about the bug in implementation of
call_once
in gcc - use conditional variable for waiting on conditions set in another threads
- know about lost and spurious wake-ups on condition variable
Agenda
- memory model in C++
-
atomic
-
memory_order
and sequential consistency -
call_once
-
condition_variable
- group exercise
- recap
Activities
- pre-work to be done before our training
- pre-test pre-test at the beginning
- exercises followed by trainers implementation
- coding dojo
- participants solutions code review
- post-work with code review
- post-test one week after the training
- certificate of completion
Duration
- 1 day (7 hours with breaks)
Form
- online
- classroom