C++ Memory Model: from C++11 to C++23 - Alex Dathskovsky - CppCon 2023

  Рет қаралды 27,914

CppCon

CppCon

2 ай бұрын

cppcon.org/
---
C++ Memory Model: from C++11 to C++23 - Alex Dathskovsky - CppCon 2023
github.com/CppCon/CppCon2023
In the realm of C++ development, threading and memory management play a crucial role in crafting highly parallel and optimized programs. However, the absence of a memory model in C++98 posed challenges. Thankfully, with the advent of C++11, significant changes were introduced, including the introduction of a memory model, which brought forth a plethora of new and exciting tools for developers to leverage. This talk aims to delve into the realm of the C++ memory model, showcasing the arsenal of tools at our disposal. Attendees will gain insights into how CPUs and compilers optimize code and understand the criticality of adhering to the memory model correctly. Practical guidelines on utilizing these tools effectively will also be explored.
Throughout the talk, we will illustrate practical examples and share best practices for utilizing the diverse set of tools now available to us. From atomic operations to memory barriers, we will explore the range of techniques that allow us to develop robust and thread-safe code.
This talk will also illustrate the newer tools from newer C++ standards like JThread and so this talk will show how memory model is used and how it advanced since C++11
---
Alex Dathskovsky
Alex has over 16 years of software development experience, working on systems, low-level generic tools, and high-level applications. Alex has worked as an integration/software developer at Elbit, senior software developer at Rafael, technical leader at Axxana, software manager at Abbott Israel, and now a group manager a technical manager at Speedata.io, an exciting startup that will change big data and analytics as we know them. In his current job, Alex is developing a new CPU/APU system working with C++20, massive metaprogramming, and the development of LLVM to create the next Big Thing for Big Data.
Alex is a C++ expert with a strong experience in template meta-programming. Alex also teaches a course about the new features of modern C++, trying to motivate companies to move to the latest standards.
---
Videos Filmed & Edited by Bash Films: www.BashFilms.com
KZbin Channel Managed by Digital Medium Ltd: events.digital-medium.co.uk
---
Registration for CppCon: cppcon.org/registration/
#cppcon #cppprogramming #cpp

Пікірлер: 33
@kodirovsshik
@kodirovsshik 2 ай бұрын
2:03 the talk starts here
@TechTalksWeekly
@TechTalksWeekly Ай бұрын
This talk has been featured in the last issue of ⭐Tech Talks Weekly newsletter. Congrats Alex! 👏
@denisfedotov6954
@denisfedotov6954 2 ай бұрын
A couple of comments: 1 Volatile variables have atomic semantics in MSVC on Windows. 2 The slide regarding compiler barriers includes a non-empty asm block with an mfence instruction. This serves as both a compiler and a memory barrier. However, an empty asm block is sufficient to be a compiler barrier (but not a memory barrier). atomic_signal_fence, as far as I know, is a standard way to express a compiler barrier.
@weiqin8494
@weiqin8494 2 ай бұрын
54:39 x86 inc is not atomic without a lock prefix. Code works because it is protected by the spin lock. Still a great usage example of acquire/release. Thanks for the great survey on concurrency support in C++.
@Roibarkan
@Roibarkan 2 ай бұрын
24:26 JF Bastien’s talk from cppcon 2019: kzbin.info/www/bejne/gXu6kHeClruLf7s
@meneldal
@meneldal Ай бұрын
Only use I have found for volatile was for accessing hardware registers. You need to tell the compiler that every read/write must really happen but you also have to make sure the cpu mmu will have flagged those memory areas as noncachable so it will actually do what you want.
@Roibarkan
@Roibarkan 2 ай бұрын
38:45 Daniel Anderson’s talk from cppcon 2023: kzbin.info/www/bejne/on-zi4lvftaiabc
@Roibarkan
@Roibarkan 2 ай бұрын
34:34 note that atomic operations are non-blocking, so in this slide Thread 2 probably needs to check that r1==1 before assigning “r2 = a;”
@12345bvbfan
@12345bvbfan Ай бұрын
Actually I saw such mistakes in lock-free data structures implementation, it's common mistake.
@Roibarkan
@Roibarkan 2 ай бұрын
38:36 Timur Doumler’s talk from cppcon 2022: kzbin.info/www/bejne/nYXTppWQbbNjpNE
@Carewolf
@Carewolf Ай бұрын
You need to keep in mind. Volatile before atomic instructions were the ONLY synchronization available in C and C++, therefore it works as such, even though the standard doesnt require it.
@yk0578
@yk0578 Ай бұрын
Re: Pop Quiz what is the memory model for CPU? if its x86 then its not possible because x86 will not reorder stores after stores. y3 should be visible before y4.
@vv78.
@vv78. Ай бұрын
Dear Alex & Co! Thank you for sharing on your knowledge. Please, Quora: Is it important to understand how computer memory works?
@calebxyz
@calebxyz Ай бұрын
Yes it is really important
@ABaumstumpf
@ABaumstumpf 2 ай бұрын
20:48 here it depends on the data-types and how they are accessed. Cause either it is a data-race and thus undefined behaviour, or all variables are atomic and thus not possible, or all variables are atomic and memory_order_relaxed is used on all operations - that is the only legal way for this to happen. std::atomic is a big mistake in the way it is formulated - and deprecating volatile is also the exact opposite of how it should be done. Volatile has a very specific meaning and it got nothing to do with "don't reorder this" or "don't optimise this" or "i need synchronisation" - and the examples for misuse of a keyword mostly boil down to people not knowing what it actually means, often due to people that know better telling them false things (like you said at 25:28). And for atomic operations it is the same thing: in no way do they mean that those operations can not be re-ordered, or that they can not be removed entirely - the only thing it means is that an operation in that memory must behave as if uninterrupted. What really would have been needed would have been 2 keywords and 1 functionality: something for atomicity - "atomic" something for dataraces - "synchronised" a simple memory-barrier - a way to specify that this step acts as a specific memory-barrier either for all or just specific memory. I have needed operations to be atomic, synchronised and volatile but rarely if ever all 3 at once. Most of the time it really was just either volatile or sychronised.
@kristiannyfjell8097
@kristiannyfjell8097 2 ай бұрын
What is it with C++ programmers thinking Volatile is used with atomics and threads? Every talk where Volatile is mentioned there is always emphasis on "stop using it with atomics!". Coming from C, that is wild to me, haha
@denisfedotov6954
@denisfedotov6954 Ай бұрын
Prior to C++11 volatiles were MS specific atomics in MSVC++.
@imrank340
@imrank340 2 ай бұрын
He did not show header file. Did he include pthread.h file? Since pthread.h file fully supported by Linux OS platform windows has it own mechanism for multi threading.
@Adowrath
@Adowrath Ай бұрын
Where in the talk would this matter since he uses std::thread?
@mendor0
@mendor0 Ай бұрын
No lib pthread here, its C++ standard primitives. All compliers should be able to translate it to proper (for OS/hardware) binaries.
@Milan_Openfeint
@Milan_Openfeint 2 ай бұрын
I guess you could skip the first 15 minutes but after that it goes quite fast.
@MaxWright7
@MaxWright7 27 күн бұрын
Pipelining and von Neumann architecture are two different things.
@realwermos
@realwermos Күн бұрын
You're right, but what architecture to optimizations like pipelining and superscalar processing apply to, then? 🤔 von Neumann is simply fetch-decode-execute, it doesn't really say how to do it, right?
@user-go5oe6td3k
@user-go5oe6td3k 2 ай бұрын
It seems like C++ threads are just painfully trying to evolve pthreads into this century. Every example cited would just be easier, cleaner and more portable if implemented with good old OpenMP. I can't see a compelling argument to use this stuff.
@soniablanche5672
@soniablanche5672 2 ай бұрын
the int i{} triggers me, why not just write int i = 0 like a normal person
@noobmartin
@noobmartin Ай бұрын
Narrowing conversion checking - sure, it's not applicable in this particular case, but I've found that it helps. :)
@Ujjawal_Gupta
@Ujjawal_Gupta Ай бұрын
Direct initialisation also helps in avoiding narrowing conversions
@pneuma1387
@pneuma1387 Ай бұрын
Because c++ coders today like to overcomplicate everything.
@Mr.Not_Sure
@Mr.Not_Sure Ай бұрын
Because later `int` can be changed to `T` template parameter.
@kovoneka
@kovoneka Ай бұрын
int i{} is one of the reasons i stopped learning this language
Getting Started with C++ - Michael Price - CppCon 2023
57:55
Women Who Code DS Talk: Feature Engineering with Hamilton
57:16
ШЕЛБИЛАР | bayGUYS
24:45
bayGUYS
Рет қаралды 601 М.
ISSEI funny story😂😂😂Strange World | Pink with inoCat
00:36
ISSEI / いっせい
Рет қаралды 26 МЛН
Surprise Gifts #couplegoals
00:21
Jay & Sharon
Рет қаралды 30 МЛН
Kris Jusiak - Embedded Reflections - emBO++ 2024
50:00
Nerd-Force1
Рет қаралды 162
Optimising Code - Computerphile
19:43
Computerphile
Рет қаралды 137 М.
you will never ask about pointers again after watching this video
8:03
Low Level Learning
Рет қаралды 1,9 МЛН
Using Libraries in C++ (Static Linking)
18:43
The Cherno
Рет қаралды 422 М.
Bjarne Stroustrup :: Approaching C++ Safety
1:16:01
CoreCppIL
Рет қаралды 18 М.
C++ Weekly - Ep 423 - Complete Guide to Attributes Through C++23
13:13
C++ Weekly With Jason Turner
Рет қаралды 9 М.
how can memory safe code STOP HACKERS?
7:43
Low Level Learning
Рет қаралды 107 М.
How about that uh?😎 #sneakers #airpods
0:13
Side Sphere
Рет қаралды 9 МЛН
How Neuralink Works 🧠
0:28
Zack D. Films
Рет қаралды 27 МЛН
Распаковка айфона в воде😱 #shorts
0:25
Mevaza
Рет қаралды 1,2 МЛН
Apple Event - May 7
38:22
Apple
Рет қаралды 6 МЛН