Introduction to CppMem

This lesson gives an introduction to the case study of ongoing optimization with CppMem.

We'll cover the following...

I will start with a small program and successively improve it, then verify each step of my process with CppMem. CppMem is an interactive tool for exploring the behavior of small code snippets using the C++ memory model.

First, here is the small program.

Press + to interact
// ongoingOptimisation.cpp
#include <iostream>
#include <thread>
int x = 0;
int y = 0;
void writing(){
x = 2000;
y = 11;
}
void reading(){
std::cout << "y: " << y << " ";
std::cout << "x: " << x << std::endl;
}
int main(){
std::thread thread1(writing);
std::thread thread2(reading);
thread1.join();
thread2.join();
}

The program is quite simple. It consists of the two threads thread1 ...