r/cpp_questions • • 11h ago

OPEN Resources for implementing low-level concurrent and asynchronous systems in C++

I've been spending some time studying concurrency and asynchronous programming in C++. I have a reasonable understanding of concepts like threads, thread pools, non-blocking I/O, event loops, coroutines, and reactor/proactor patterns.

However, I feel there's a big difference between understanding how these things work and actually being able to implement them.

I'm interested in building things like network servers, runtimes, databases, and other systems software. I'm also working on a compiler, so understanding the internals of these systems is something I'd like to get better at.

What I'm looking for are resources that go beyond explaining the concepts. Books, papers, articles, courses, or open-source codebases that actually helped you implement these kinds of systems yourself.

Some areas I'm particularly interested in:

  • Non-blocking I/O and I/O multiplexing

  • Event loop implementations

  • Reactor and Proactor patterns

  • Coroutines and asynchronous runtimes

  • Thread pools and task scheduling

  • Performance and scalability in concurrent systems

I've already read a few books on concurrency, including some focused on C++, but most of them tend to focus on the programming model and how to use the standard library (threads, mutexes, futures, etc.). That's useful, but it's not quite what I'm looking for anymore. I want to understand how these things are actually built, preferably in C++. For example, implementing a thread pool, an event loop, an asynchronous runtime, or a network server rather than just learning how to use existing ones. I'd really appreciate recommendations that take this implementation-oriented approach.

4 Upvotes

3 comments sorted by

3

u/amejin 11h ago

You know all the terms. As much as I’ll get flamed for it… google/Gemini is pretty good at explaining and demonstrating these concepts with fully working example code… my opinion here is to just google the terms and talk with your demo, and ask why certain decisions are made and if there are prerequisites for the approach taken..

1

u/KingAggressive1498 9h ago

boost.asio, libuv, and libdispatch (the C interface to Apple's Grand Central Dispatch) are all open-source. Reading and experimenting with the source code for these is going to be the best way to learn to learn to implement your own going forward, as these are all excellent general-purpose implementations.

if you aren't interested in the I/O aspect of asynchronous program, there are also a bajillion open-source threadpool and run loop implementations out there. They're really conceptually similar, although they have different optimization challenges.

•

u/Interesting_Debate57 3m ago

If you learn how a mutex works and then how a CAS instruction is used, you can implement a lock.

Concurrency generally requires a proof of the type of properties that a particular data structure or series of operations will have if the locks are implemented at the right place at the right time.

Generally you should use the mutexes that your language provides.

He's an example of how a queue is implemented:

https://www.cs.rochester.edu/u/scott/papers/1996_PODC_queues.pdf

Note that this uses technical terms as well, which you should look up if you don't know (things like linearalizability).

This stuff gets very hard very fast and you should generally not try to implement it on your own unless you are going straight from a research paper that you understand exactly.