Skip to content
0:00 / 0:00

#c++#atomics#memorymodel

C++ and Beyond 2012: Herb Sutter - atomic Weapons 1 of 2

alexsmail

7.9K subscribers • 3 videos on Hallway

YouTube
  • Recommended by 4 people: 4 on Hacker News.
  • A classic. People kept recommending it from 2020 to 2024.
  • Presented by Herb Sutter

Advanced. Deep dive for people who know the field.

71K views8 years ago4 recommendations

Systems programmingProgramming languagesC++Concurrency and parallelismMemory management

Herb Sutter explains the C++11 memory model, hardware ordering, and how atomic operations work under the hood.

channel9.msdn.com/Shows/Going+Deep/Cpp-and-Beyond-2012-Herb-… Download the slides. 1drv.ms/b/s!Aq0V7yDPsIZOgcI0y2P8R-VifbnTtw Abstract: This session in one word: Deep. It's a session that includes topics I've publicly said for years is Stuff You Shouldn't Need To Know and I Just Won't Teach, but it's becoming achingly clear that people do need to know about it. Achingly, heartbreakingly clear, because some hardware incents you to pull out the big guns to achieve top performance, and C++ programmers just are so addicted to full performance that they'll reach for the big red levers with the flashing warning lights. Since we can't keep people from pulling the big red levers, we'd better document the A to Z of what the levers actually do, so that people don't SCRAM unless they really, really, really meant to. Topics Covered: * The facts: The C++11 memory model and what it requires you to do to make sure your code is correct and stays correct. We'll include clear answers to several FAQs: "how do the compiler and hardware cooperate to remember how to respect these rules?", "what is a race condition?", and the ageless one-hand-clapping question "how is a race condition like a debugger?" * The tools: The deep interrelationships and fundamental tradeoffs among mutexes, atomics, and fences/barriers. I'll try to convince you why standalone memory barriers are bad, and why barriers should always be associated with a specific load or store. * The unspeakables: I'll grudgingly and reluctantly talk about the Thing I Said I'd Never Teach That Programmers Should Never Need To Now: relaxed atomics. Don't use them! If you can avoid it. But here's what you need to know, even though it would be nice if you didn't need to know it. * The rapidly-changing hardware reality: How locks and atomics map to hardware instructions on ARM and x86/x64, and throw in POWER and Itanium for good measure – and I'll cover how and why the answers are actually different last year and this year, and how they will likely be different again a few years from now. We'll cover how the latest CPU and GPU hardware memory models are rapidly evolving, and how this directly affects C++ programmers. For more information see alexsmail.blogspot.com/2017/11/c-and-beyond-2012-herb-sutter…

Why it's here

4 people recommend this

What people say. Recommended as the definitive deep dive into the C++ memory model and atomic operations.

Sharlinon Hacker News • Recommends

On “Swift Atomics”

If you’re prepared and willing to learn much more about atomic operations than you ever thought you would, there’s no substitute to Herb Sutter’s classic talk ”atomic<> Weapons” from C++ And Beyond 2012 1. 1 link to this video

NobodyNadaon Hacker News • Recommends

On “C++ Memory Model: Migrating from x86 to ARM”

For a more in depth introduction to the topic with a lot of practical code examples, I highly recommend Herb Sutter’s excellent talk: Part 1 link to this video Part 2 link

zevvon Hacker News • Recommends

On “Making Sense of Acquire-Release Semantics”

…ith senior programmers who have spent their careers carelessly threading their code without realizing what is happening under the hood. Not only did some of them not properly understand the acquire/release model, but they were not even aware of its existence. For a more in-depth explanation, I recommend Sutter's excellent talk "Atomic <> weapons": link to this video . It is a two hour lecture, but it will be worth your time.…

chc4on Hacker News • Recommends

On “Rust Atomics and Locks (2023)”

"Is Parallel Programming Hard, And, If So, What Can You Do About It?" is one of the best books about atomics and concurrency, and my #2 recommendation. link My #1 actually isn't a book at all, but the two "atomic Weapons" talks by Herb Sutter, which are extremely good. link to this video link

Sharlinon Hacker News • Recommends

On “C++ Concurrency Model on x86 for Dummies (2020)”

For a somewhat less "for dummies" treatment of the C++ memory model, see Herb Sutter's classic talk "atomic<> Weapons" 1. 1 link to this video

u/Nervous_Recursionin r/C_Programming • Mentions

On “Where can one learn about Std threads, Atomic operations, lock free / wait free programming as well as distributed parallel programming where each core has its own memory space that is total mem / total core in C?”

The C11 memory model is essentially the same as the C++11 one, so if you are starting from scratch, learn why it was designed that way and the principles behind, it is equally valid for C. The following talk from Herb Sutter is very good: * link to this video * link to this video It's not so much about each language implementation themselves (he only cites the memory models of Java, C++ and C and some subtle differences), but explains why you need to care about defining this memory model in the first place in the context of concurrency. It was delivered at a C++ con but don't let it stop you, it's a good material to get into this subject IMO.

u/skyb0rgin r/C_Programming • Mentions

On “Help with debugging a multi-thread data structure - Understanding TSan”

I’m mainly agreeing with Herb Sutter in stating that “atomics are hard, non-seq-cst atomics are impossible”. I’m not using this in production, so hopefully there isn’t much of a slowdown.

u/AnonymousMorrisin r/C_Programming • Mentions

On “Learning programming isn't like Math.”

So true. Reading a blog about systems programming from 10 years ago hits differently. They were so information dense and insightful compared to what we have now. On the topic of computer architecture and because OP mentioned semaphores. I recommend giving this a watch link to this video