The class
jthread provides a mechanism
to create a new thread of execution
. The functionality is the same as for
class
thread (
[thread.thread.class])
with the additional abilities to provide
a
stop_token (
[thread.stoptoken]) to the new thread of execution,
make stop requests, and automatically join
.namespace std {
class jthread {
public:
using id = thread::id;
using native_handle_type = thread::native_handle_type;
jthread() noexcept;
template<class F, class... Args> explicit jthread(F&& f, Args&&... args);
~jthread();
jthread(const jthread&) = delete;
jthread(jthread&&) noexcept;
jthread& operator=(const jthread&) = delete;
jthread& operator=(jthread&&) noexcept;
void swap(jthread&) noexcept;
[[nodiscard]] bool joinable() const noexcept;
void join();
void detach();
[[nodiscard]] id get_id() const noexcept;
[[nodiscard]] native_handle_type native_handle();
[[nodiscard]] stop_source get_stop_source() noexcept;
[[nodiscard]] stop_token get_stop_token() const noexcept;
bool request_stop() noexcept;
friend void swap(jthread& lhs, jthread& rhs) noexcept;
[[nodiscard]] static unsigned int hardware_concurrency() noexcept;
private:
stop_source ssource;
};
}