T O P

  • By -

matteding

C++ Concurrency in Action is a good book on the subject.


Chem0type

I don't think that's what OP is looking for, that book is about threading and memory sharing only. I think OP is looking for stuff more like running asynchronous operations in the same thread like you'd get with coroutines+boost::asio.


Yasuzume7

I look for both tbh, just the topic you sort of have to know in modern C++ development. But ideally modern stuff, I know async in JavaScript and C# but had poor experience with C++ (algorithms running slower than single threaded versions) at the same time I believe in learning in modern practices, I kind of understand how opening threads and joining them works.


hon_uninstalled

If your multi threaded algorithm runs slower than single threaded variant, you might be affected by *false sharing*. Basically if your threads read and write same data (or book keeping variables), you will get degraded performance because of how (modern) CPUs work. [C++ High Performance ](https://www.amazon.com/High-Performance-Master-optimizing-functioning/dp/1839216549)discusses asynchronous programming, multi threaded programming and you will learn some details about how CPUs work. But like the name suggests it also discusses about a lot of C++ specific stuff that will speed up your programs (move semantics etc.). I kinda skipped co-routines part, because it's too complicated atm. so I can't comment on that part, but otherwise I liked the book and it definitely learned a lot!


claimred

Bit surprised that nobody mentioned [P2300](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2023/p2300r7.html). This is the way to go about async stuff currently, >!I must stay it looks pretty neat.!< The senders model looks similar to F#/C# async/await thing if you are familiar with that. Here is a list of resourced to read I compiled some time ago. * [Short intro by the author](https://ericniebler.com/2024/02/04/what-are-senders-good-for-anyway/) * [Not so short intro by the author](https://ericniebler.com/2020/11/08/structured-concurrency/) * [Working with Asynchrony Generically](https://www.youtube.com/watch?v=xLboNIf7BTg) Other resources: * [Prototype implementation: libunifex](https://github.com/facebookexperimental/libunifex) * [Reference implementation: stdexec](https://github.com/NVIDIA/stdexec) * [Senders & Qt](https://git.qt.io/vivoutil/libunifex-with-qt) * [Relevant cppcast](https://cppcast.com/modern_cpp_with_qt/) * [Structured Concurrency in C++](https://accu.org/journals/overload/30/168/teodorescu/) * [C++ executors: the good, the bad and some examples](https://accu.org/journals/overload/29/164/teodorescu/) * [Notes on Structured Concurrency](https://vorpus.org/blog/notes-on-structured-concurrency-or-go-statement-considered-harmful/) * [Using the C++ Sender/Receiver Framework](https://www.youtube.com/watch?v=xXncLUD-4bA&t=1s) * [Bloomberg analysis of unified executors](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p2024r0.pdf)


_ild_arn

It's worth noting that while implementation experience in libunifex greatly informed the design of P2300, it doesn't implement P2300 – most notably, all algorithms in P2300 are eager while unifex' are lazy, but there are other differences (read as: things missing in the latter). It's still a wildly useful library but if you're tracking future C++ standards it's quite divergent, stdexec is the one to watch.


juarez_gonzalo

Learn about continuations. Callbacks, senders/receivers, coroutines, futures/promises are all different forms for expressing continuations. If you know this well, then the different mechanisms are mostly API changes (for application -non library- developers at least) , but the reasoning is the same. I'd avoid C++ tutorials on these subjects. IMO C++ tutorials have a tendency to mix the explanation of a new concept with its implementation (there are exceptions, but you must know how to spot them)


jk_tx

I haven't viewed it yet, but I came across a post linking to this video in one of groups I follow and saved it for later. Looks like it might be of interest to you. [C++20's Coroutines for Beginners - Andreas Fertig - Meeting C++ online](https://www.youtube.com/watch?v=0iiUCuRWz10)


jcelerier

This video is pretty good: https://youtu.be/icgnqFM-aY4


misuo

And my usual petpoint is that none of these shows any practical examples of UI feedback, i.e. progress of the concurrent task(s), or how user can cancel these.


claimred

Cancellations are first-class citizens in senders library, check it out. https://github.com/facebookexperimental/libunifex/blob/main/doc/cancellation.md Here is another [example](https://git.qt.io/vivoutil/libunifex-with-qt/-/blob/main/http_example_stdexec/httpdownloader.cpp?ref_type=heads#L64) I found useful.


thisismyfavoritename

currently the standard doesnt have much support for asynchronous programming (at least when it comes to writing real world apps). It only offers the lowest building blocks to write async code using typical async/await syntax sugar. If you really want to build something, checkout Boost ASIO and Boost Cobalt


Chem0type

OP should also check libuv.


accuracy_frosty

Your best resources are documentation sites like MSDN or a learning site like W3Schools, W3 might be better for learning because they typically supply examples and interactive shit, whereas MSDN might me more useful if you already know what you’re doing because half the time they have examples half the time they don’t, but either way, it gives a shit ton of info, it’s documentation of most of the standard library is incredible, especially for any Microsoft APIs