This was the first time I was at the CppCon, and it was an overwhelming experience for me.
I gave one of the two days pre-conference classes. Other classes were given by Nicolai Josuttis, Alexandrei Alexandrescu, and Scott Meyers. My class "Multithreading with Modern C++" went very well. I had more than 30 very active participants. The first day was about the basic stuff such as threads, tasks, locks, and condition variables. The second day was more experimental. We discussed atomics, the memory model, and verified our code with the interactive C/C++ memory model checker CppMem. I also made a detour to the Parallel Standard Template Library and the concurrent future (C++20/23) of C++.
Here are my impressions and the talks I enjoyed the most. You should watch them on YouTube in a few weeks.
Keynote: Concepts: The Future of Generic Programming by Bjarne Stroustrup (MD, MorganStanley)
Bjarnes talk was not technical but presented the key ideas as the design principles of concepts. He started his presentation with the motivation and history of concepts. Concepts have a long history in C++. Alexander Stepanov (father of the Standard Template Library) with his book Elements of Programming is their main inspiration.
Bjarne also talked about the benefits of concepts. We will get specific error messages, specify our intent, make our code more readable, and give the compiler optimisation hints.
Concepts are compile-time predicates the should not model minimal requirements such as
HasAdd but support interoperability. Concepts are not typed of types such as type classes, because they can take types and values. Now the question is. What should concepts look like? Concepts can model mathematical ideas such as group or ring, but also concrete ideas such as Number or Sortable. You can define your one concept or build concepts based on existing ones. Bjarne also answered the question: What are their design principle:
- Provide good interfaces.
- Look for semantic coherence.
- Don't force users to do what machines do better.
- Keep simple things simple
Once more. This was a great keynote because of the big picture about concepts.
The C++ Execution Model from Bryce Adelstein Lelbach (Senior Software Engineer, NVIDIA)
In contrast to the keynote, Bryce talk was quite technical and quite advanced. Bryce explained terms that are essential to get a solid understanding of the execution of a single-threaded and also multithreading program. He explicitly excluded the infamous memory order std
First of all, there is the as-if rule. This means the system (compiler, processor, memory) can perform all optimisations which do not change the observable behaviour of a single-threaded program.
Bryce presented the C++ standard as an abstract machine, talked about threads and threads of execution and defined terms such as expression, evaluation, side-effect, sequenced-before, execution steps, and forward progress. Let me refer to the term sequenced-before. In the single-threaded case, sequence-before causes a happens-before relation. In the multi-threaded cases, a happens-before relation is created by synchronize-with. In essence, without a happens-before relation, your multi-threading program has a data race. Bryce talk was quite advanced but also quite comfortable for me because I use these terms in my presentations or workshops to the memory model.
Why and How to Roll Your Own std::function Implementation by Tom Poole (Senior Software Developer, ROL)
To make it short. Tom's talk was this kind of presentation I like very much. First, the entire talk was advanced but not too advanced. Second, I learned a lot about implementing
::function is a polymorphic wrapper for callables in C++ such as function, function objects, or lambda functions.
Tom Poole is a maintainer of the JUCE open source, cross-platform, C++ framework for audio applications. Due to the unique performance and memory requirements and the fact, that
std::function is not available on all platforms, JUCE support an own version of
std::function. Tom presented the challenges of implementing it.
These challenges included the avoidance of dynamic memory allocations, locks, but also type erasure. In the end, he had an implementation which a performance comparable to the performance of
Sane and Safe C++ Class Types from Peter Sommerlad (Professor, HSR Rapperswill)
First, Peter used sane and safe to divide types into four categories. Based on his categorisation, he discussed types.
Sane and Safe
With empty types or values types (regular types), we are in the sane and safe category. But this does not hold for plain pointers, polymorphic types, or built-in types such as (
bool, int, double's).
In-sane and In-safe
They are in-sane and in-safe. Maybe you wonder, why builtin-types belong to this category. The reason is quite easy. They can be victims of integral promotion, numeric conversions, or have special values such as +Inf, -Inf, or NaN. To make a built-in type-safe and sane, use the Whole Value Pattern from Ward Cunningham. The question is? What is sane and in-safe.
Sane and In-safe
For example, pointing types such as iterators, smart pointers, references, reference wrappers, or views (
std::string_view) are sane and in-safe. With C pointers we are in the in-sane and in-safe ar
This was a great talk that should be part of each C++ curriculum!
Thanks to Jon Kalb, I was on Thursday with Jason Turner and Dan Saks at a trainer panel. With had 60 minutes to talk about our training and answered a lot of questions from the audience.
What do you mean thread-safe? by Geoffrey Romer (Software Engineer, Google)
Maybe you want to know why I visited this talk? The reason is that a well-defined terminology is key in multithreading programs. Often issues in multithreaded programs arise because people understand a different thing by using the same terms. First of all, Geoffrey used the term API race instead of data race which is used by the standard.
- API race: The program performs two concurrent operations on the same object when the object's API doesn't permit those operations to be concurrent.
The difference between an API race to a data race is that a data race occurs if a read and a write operation happen at the same time on the same memory location. This definition of a data race includes two write operations. An API talks about operations that should not be performed concurrently on the same object.
The focus of the terms is mainly about types and not about functions. Each type belongs to one of the three following categories.
- If a live object has a thread-safe type, it can't be the site of an API race.
- If a live object has a thread-compatible type, it can't be the site of an API race if it's not being mutated.
- The remaining objects are not thread-compatible.
An atomic value is an example for category one and a const variable for category two.
Here are final tips from Geoffrey: Have thread-safe types or immutable thread-compatible types if necessary.
Although I can not write so much about this 30 minutes talk, it was fascinating. I understand during his talk that we need a well-defined terminology for our types to reason about multithreading programs.
My Last Words
Two days pre-conference class, five days conference, this was quite an overwhelming experience for me and, to be honest, quite exhaustive. Of course, the talks were great and I learned a lot but this not my main takeaway. I loved the personal talks I had during and after the conference. I had a lot of talks with people I know for a few years but never meet personally. Once more thanks a lot for inviting me, Jon.
Thanks a lot to my Patreon Supporters: Matt Braun, Roman Postanciuc, Tobias Zindl, G Prvulovic, Reinhold Dröge, Abernitzke, Frank Grimm, Sakib, Broeserl, António Pina, Sergey Agafyin, Андрей Бурмистров, Jake, GS, Lawton Shoemake, Animus24, Jozo Leko, John Breland, Venkat Nandam, Jose Francisco, Douglas Tinkham, Kuchlong Kuchlong, Robert Blanch, Truels Wissneth, Kris Kafka, Mario Luoni, Friedrich Huber, lennonli, Pramod Tikare Muralidhara, Peter Ware, Daniel Hufschläger, Alessandro Pezzato, Bob Perry, Satish Vangipuram, Andi Ireland, Richard Ohnemus, Michael Dunsky, Leo Goodstadt, John Wiederhirn, Yacob Cohen-Arazi, Florian Tischler, Robin Furness, Michael Young, Holger Detering, Bernd Mühlhaus, Matthieu Bolt, Stephen Kelley, Kyle Dean, Tusar Palauri, Dmitry Farberov, Juan Dent, George Liao, Daniel Ceperley, Jon T Hess, Stephen Totten, Wolfgang Fütterer, Matthias Grün, Phillip Diekmann, Ben Atakora, and Ann Shatoff.
Thanks in particular to Jon Hess, Lakshman, Christian Wittenhorst, Sherhy Pyton, Dendi Suhubdy, Sudhakar Belagurusamy, Richard Sargeant, Rusty Fleming, John Nebel, Mipko, Alicja Kaminska, and Slavko Radman.
My special thanks to Embarcadero
My special thanks to PVS-Studio
My special thanks to Tipi.build
I'm happy to give online seminars or face-to-face seminars worldwide. Please call me if you have any questions.
Standard Seminars (English/German)
Here is a compilation of my standard seminars. These seminars are only meant to give you a first orientation.
- C++ - The Core Language
- C++ - The Standard Library
- C++ - Compact
- C++11 and C++14
- Concurrency with Modern C++
- Design Pattern and Architectural Pattern with C++
- Embedded Programming with Modern C++
- Generic Programming (Templates) with C++
- Clean Code with Modern C++
- Phone: +49 7472 917441
- Mobil:: +49 176 5506 5086
- German Seminar Page: www.ModernesCpp.de
- Mentoring Page: www.ModernesCpp.org