Back to Basics: C++ Concurrency - David Olsen - CppCon 2023

preview_player
Показать описание
---

Back to Basics: C++ Concurrency - David Olsen - CppCon 2023

Concurrent programming unlocks the full performance potential of today's multicore CPUs, but also introduces the potential pitfalls of data races and random, difficult-to-debug application failures. This back-to-basics session will provide a foundation for concurrent programming, focusing on std::thread and mentioning other ways to introduce concurrency and parallelism. A lot of time will be spent on how to recognize data races, and how to avoid them using mutexes, atomic variables, and other standard constructs.

Attendees will come away knowing how to write simple and correct concurrent programs and will have a foundation to build on when developing more complex concurrent applications.
---

David Olsen

David Olsen has more than two decades of software development experience in a variety of programming languages and development environments. For the last seven years he has been the lead engineer for the NVIDIA HPC C++ compiler, focusing on running standard parallel algorithms on GPUs. He is a member of the ISO C++ committee, where he was the champion for the extended floating-point feature in C++23.
---

---

#cppcon #cppprogramming #cpp #concurrency
Рекомендации по теме
Комментарии
Автор

Great talk, introduces enough concepts to cover many concurrency applications while hinting at more advanced topics. Highlights the most useful parts of the C++ API without drowning us in petty detail. Illustrates abstract structures with analogies that actually make sense and that are EXPLAINED. What a champ.

TimothyZhou
Автор

17:58 Drinking and breathing race condition. Happens to the best of us 😅.

bunpasi
Автор

This is probably the most complete video on concurrency and parallelism there is. Definitely going to bookmark this to recommend. The only thing it needs is more time to flesh out all of the other concepts he brought up at the end, and to talk about compiler support. Otherwise, I love that he provides examples, and that they actually work. Compiler Explorer is a Godsend for this.

anon_y_mousse
Автор

Fascinating complications! Thank you very much for unpacking them 🙏

VoidloniXaarii
Автор

42:47 To avoid holding locks more than necessary I think each thread can hold only one lock for the first change_data, *unlock it* and *then* (re)lock both together:
Thread 1
{
std::scoped_lock{mutex_a};
change_data(data_a);
} {
std::scoped_lock{mutex_a, mutex_b};
change_data(data_a, data_b);
}
Thread 2
{
std::scoped_lock{mutex_b};
change_data(data_b);
} {
std::scoped_lock{mutex_a, mutex_b};
change_data(data_a, data_b);
}

yurkoflisk
Автор

Great talk for "Back to Basics of C++ Concurrency". We also have a great talk on the very same topic by Anthony Williams if you haven't watched it yet. Now, I'll be waiting for "Back to Advanced C++ Concurrency".

briansalehi
Автор

My takeaway

Concurrency: Multiple logical threads of execution with some inter-task dependencies
- Doing things at the same time
- Some things need to happen before other things
- Some things can't happen at the same time

Parallelism: Multiple logical threads of execution with no inter-task dependencies

Data Race:
1. Two or more threads access the same memory
2. At least one access is a write
3. The threads do not synchronize with each other
A data race is undefined behavior

xrtgavin
Автор

please add subdivision into parts like other back to basics video !

Benben-juvo
Автор

std::parallel algorithms can't "just be used" right? You have to have an implementation from the *outside* to make it work on clang and GCC right? This has basically made them dead in the water for a lot of code that doesn't *just* target MSVC because of the reliance on intel TBB that doesn't come bundled with the code base and doesn't work on ARM . Until it becomes a *zero install* solution, parrallel algorithms for all popular platforms on linux is basically not a "just use it and forget" thing like implied by this presentation.

snbvreal
Автор

It's very funny to hear an advice to use jthread not having it in the last llvm libc++ 17. It seems that C++ lives its own life while LLVM falls far behind the language.

alexeysubbota
Автор

(1) Great talk! (2) 46:45 - for this particular example I believe marking flag as volatile would have been better than atomic. This would have prevented compilers optimizing the while-loop away, and bools are inherently atomic anyway. Am I missing something?

abuyoyo
Автор

That was a really good talk on concurrency! Thanks David and CppCon.

balajimarisetti
join shbcf.ru