Skip to content

The Two Memory Models with Anders Schau Knatten

Photo of Anders Schau Knatten
Hosted By
Anders Schau K.
The Two Memory Models with Anders Schau Knatten

Details

Squarehead is hosting this event.

The office is located two minutes from Nydalen T-bane in Nydalsveien 28, 0484 Oslo.

Timetable
- 17:00 : Food and mingling
- 17:30 : The Two Memory Models by Anders Schau Knatten

The Two Memory Models
Programming languages like C, C++, and Rust all define a memory model, which allows you to reason about the ordering of memory operations in your program. This is crucial for the correctness and speed of your multithreaded programs, whether you're using good old mutexes or lock-free algorithms. But did you know that your CPU also has a memory model?
In the first part of this talk, we review some examples of C/C++, both single- and multithreaded, including a common lock-free algorithm. We examine the compiler-generated Assembly code and gain an intuition for how much reordering the compiler and the CPU are allowed to do. We then discuss what C++ means by a data race and how to avoid them using atomics and memory orderings like sequentially consistent, relaxed, acquire, and release. We also see how C++ reasons about memory ordering in terms of happens-before relationships.
In the second part of the talk, we examine the CPU memory models and what we mean by reordering of memory operations. There are many sources of reordering, such as the compiler, the CPU pipeline, micro-ops, memory systems with store buffers and coalescing, caches, etc. We then see how CPUs reason about memory ordering differently than languages like C++ and Rust and how the CPU memory models enable the language memory models to work. We also see how x86, ARM, and RISC-V have different approaches to this.
At the end of this talk, you will have gained a better understanding of what guarantees your programming language gives you and how the CPU works under the hood to allow your programs to (safely) go vroom! You will also have learned not to make assumptions about the correctness of your code by simply looking at the Assembly code.

Anders Schau Knatten
Anders started programming in Turbo Pascal in 1995, and has been programming professionally in various languages since 2001. He's currently a senior software engineer at Squarehead, working on counter-drone audio tech. He's the author of the book C++ Brain Teasers, cppquiz.org and the blog C++ on a Friday

Photo of Oslo C++ Users Group group
Oslo C++ Users Group
See more events
Respond by
Sunday, June 15, 2025
2:00 PM
Squarehead
Nydalsveien 28, 0484 Oslo · Oslo
Google map of the user's next upcoming event's location
FREE