C++ Coroutines from scratch -Andreas Fertig - NDC TechTown 2023
ฝัง
- เผยแพร่เมื่อ 21 ธ.ค. 2024
- This talk was recorded at NDC Techtown in Kongsberg, Norway. #ndctechtown #ndcconferences #cplusplus #developer #softwaredeveloper
Attend the next NDC conference near you:
ndcconferences...
ndctechtown.com/
Subscribe to our TH-cam channel and learn every day:
/@NDC
You've heard about this new feature in C++20, Coroutines, but it's the first time you have encountered this term? Then this talk is what you're looking for. We start from the beginning with just "normal" functions. Next, we introduce Coroutines.
Using them, we explore the various customization points C++ offers. We look at what the new keywords co_await, co_yield, and
co_return are for.
Sadly, we also have to talk about how to write a generator for a coroutine since there is no STL part for that in C++20.
Another distinction we make is between cooperative and preemptive multitasking, opening the door for another beauty of
Coroutines, why we don't need locks.
By the end of this talk, you've learned what coroutines are and where you can use them.
30:18 That seems like a lot of boilerplate for a coroutine, especially compared to other languages with similar functionality.
This example shows how to write a coroutine on top of bare-bones c++. Given a good library (e.g. Cppcoro) it's much simpler to implement coroutines
1:02:20 This doesn't seem to have been responded to at all. Is it actually true? I wish this had gotten more info because I'm not even clear on what he was trying to ask.
It’s living hell, sorry
I though so, too.
Then I began compiling my knowledge and experience for others in my team/project to follow. That made me think differently about it. And coroutines became easier to deal with.
But it requires some caution, especially in complex scenarios.
@@mikem.s.1183 I'm doing that now for my team. Do you have any recommended sources - articles/videoes/etc? I'm finding the large range of customization of it to be a barrier of confusion (as someone said, it's a bad sign when the community are yet to agree on a Hello-World example for coroutines)
@@Gherzahn
My role (in a scrum based team for an automotive big one) was twofold: provide good code/documentation with as much detailed analysis I could muster, and also mentor the less experienced programmers.
What I did while building a MS Team's based wiki for "tough" subjects, among them coroutines:
- searched for coroutines where it is being pushed a lot, C++ related sites and Kotlin. The concepts of both are identical.
- I gave attention to definitions, concepts and then proceeded to a variety of examples in both languages
- I also added some interoperability between different languages (Python, Go, C++ and Kotlin)
- I explored the topic Kotlin Coroutines vs Java Virtual Threads (the team had experience in C++, Kotlin and Java).
This helped the team.
We had junior devs, mid-level devs and only 2 super seniors (programmers with 25+ years of experience). Because everyone was invited to comment, share doubts and add to that Wiki (with sessions (remotely or otherwise) with some 3 devs programming and exchanging tips or issues), we managed to move ahead. The guys were also very interested.
Few things I always do:
1- I don't stick to one source. Or two, or three.
2- Initially, I don't resort to explaining things based off my experience/knowledge.
There's no simple way around this and other similar topics, I think.
I hope this helps a little.
I think it is a fantastic feature which will only get better in the next c++ standards.
I'm a quarter of the way into this video and I'm smelling some C#. Bit funny how C# has await/yield keywords. Oh and later on he's got "not" and "or". This is definitely someone that should be writing C#, not demonstrating pointless and overly complicated C++ features that nobody wants or asked for.
Like many people, we pick the best features from the various standards to make nicer code, so coroutines has better have some sizable advantages to make me adopt them. Also, they need to not be confusing to people, or they're not going to get used.
Am halfway through and can now say that it's all just a load of crap without any tangible benefit. It's like the C++ standards committee ran out of ideas and came up with this abomination.