Each accepted connection is currently handled by a std::thread. We can use C++20 now, which offers std::jthread. In addition to the resource management benefits, it also supports cooperative cancellation (stop_token) which should improve the way interruption of connections is handled (i.e., Ctrl-C is passed and the threads need to go away swiftly).
In short, we should consider using:
- jthread
- std::stop_source/token with the jthreads.
- std::condition_variable_any with the std::stop_token