Skip to content
0:00 / 0:00

#atomics#memory-ordering#lock-free

CppCon 2017: Fedor Pikus “C++ atomics, from basic to advanced. What do they really do?”

CppCon

189K subscribers • 103 videos on Hallway • Conference channel

YouTube
  • Recommended by 3 people: 3 on Hacker News.
  • A classic. People kept recommending it from 2017 to 2025.
  • Presented by Fedor Pikus
  • Linked in the descriptionCppCon/CppCon2017

Advanced. Deep dive for people who know the field.

288K views9 years ago3 recommendations

Systems programmingProgramming languagesC++Concurrency and parallelismMemory management

Fedor Pikus explains C++ atomic operations, comparing what they express in code to how compilers and hardware execute them.

CppCon.org — Presentation Slides, PDFs, Source Code and other presenter materials are available at: github.com/CppCon/CppCon2017 — C++11 introduced atomic operations. They allowed C++ programmers to express a lot of control over how memory is used in concurrent programs and made portable lock-free concurrency possible. They also allowed programmers to ask a lot of questions about how memory is used in concurrent programs and made a lot of subtle bugs possible. This talk analyzes C++ atomic features from two distinct points of view: what do they allow the programmer to express? what do they really do? The programmer always has two audiences: the people who will read the code, and the compilers and machines which will execute it. This distinction is, unfortunately, often missed. For lock-free programming, the difference between the two viewpoints is of particular importance: every time an explicit atomic operation is present, the programmer is saying to the reader of the program "pay attention, something very unusual is going on here." Do we have the tools in the language to precisely describe what is going on and in what way it is unusual? At the same time, the programmer is saying to the compiler and the hardware "this needs to be done exactly as I say, and with maximum efficiency since I went to all this trouble." This talk starts from the basics, inasmuch as this term can be applied to lock-free programming. We then explore how the C++ lock-free constructs are used to express programmer's intent clearly (and when they get in the way of clarity). Of course, there will be code to look at and to be confused by. At the same time, we never lose track of the fact that the atomics are one of the last resorts of efficiency, and the question of what happens in hardware and how fast does it happen is of paramount importance. Of course, the first rule of performance — "never guess about performance!" — applies, and any claim about speed must be supported by benchmarks. If you never used C++ atomics but want to learn, this is the talk for you. If you think you know C++ atomics but are unclear on few details, come to fill these few gaps in your knowledge. If you really do know C++ atomics, come to feel good (or to be surprised, and then feel even better). — Fedor Pikus: Mentor Graphics - Siemens business, Chief Scientist Fedor G Pikus is a Chief Engineering Scientist in the Design to Silicon division of Mentor Graphics Corp. His earlier positions included a Senior Software Engineer at Google and a Chief Software Architect for Calibre PERC, LVS, DFM at Mentor Graphics. He joined Mentor Graphics in 1998 when he made a switch from academic research in computational physics to software industry. His responsibilities as a Chief Scientist include planning long-term technical direction of Calibre products, directing and training the engineers who work on these products, design and architecture of the software, and research in new design and sof

Why it's here

3 people recommend this

What people say. Highly recommended as an excellent, clear explanation of lock-free programming, memory barriers, and hardware cache behavior.

spepson Hacker News • Recommends

On “Designing a Lock-free, Wait-free Hash Map”

No, from what I understand, you can't even do it in software anyway due to how the caches work between cores inside the CPU. Watching this was enlightening to say the least (and the presenter is very good): link to this video

chrsigon Hacker News • Recommends

On “Lockfree Algorithms (2010)”

Fedor Pikus has given a number of great talks on the subject at cppcon over the years some links, in no particular order: CppCon 2017: Fedor Pikus “C++ atomics, from basic to advanced. What do they really do? link to this video CppCon 2016: Fedor Pikus “The speed of concurrency (is lock-free faster?)" link CppCon 2015: Fedor Pikus PART 1 “Live Lock-Free or Deadlock (Practical Lock-free Programming)" link CppCon 2015: Fedor Pikus PART 2 “Live Lock-Free or Deadlock (Practical Lock-free Programming)” link CppCon 2017: Fedor Pikus “Read, Copy, Update, then what? RCU for non-kernel programmers” link Tony Van Eerd has also given some talks on lock free queues, I'll leave it as an exercise to the read…

inetknghton Hacker News • Recommends

On “Without the futex, it's futile”

…hael Wong's 2015 presentation 0 filled in some of the gaps. C++, being a generic language for many hardware implementations, provides a lot more detailed concepts for memory ordering 2, which is important for hardwares that have more granularity in barrier types that what most people are used to with x86-derived memory models. 0: link 1: link to this video 2: link…

u/N-R-Kin r/C_Programming • Mentions

On “Misc of C Programming”

I do maintain a private list of articles/videos that I find useful. It's too messy to copy paste in it's entirety, so I'll pick out some of the good ones here: - Quick references: * https://en.cppreference.com/w/c (can be downloaded to be viewed offline as well!) * http://www.c-faq.com * https://port70.net/~nsz/c/ contains drafts of various C standards - Memory management: * Handles are the better pointer * Memory allocation strategies (some of the code shown are a bit over-engineered IMO, but the principle is good) * Untangling Lifetimes: The Arena Allocator - Concurrency: * Hardware memory model * Futexes are tricky * [C++ atomics, from basic to advanced. What do they really do…

u/optimistic_voidin r/C_Programming • Mentions

On “One-writer many-readers flag-- is atomic_bool necessary?”

I have recently watched a video that contained a decent explanation of memory barriers and ordering, althought it is c++ I think it still relatable, here , skip to around 43 min.