Skip to content

Convert std::thread to std::jthread with cooperative cancellation #237

@bneradt

Description

@bneradt

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions