29#ifndef _GLIBCXX_THREAD
30#define _GLIBCXX_THREAD 1
32#pragma GCC system_header
34#if __cplusplus < 201103L
38#if __cplusplus > 201703L
46namespace std _GLIBCXX_VISIBILITY(default)
48_GLIBCXX_BEGIN_NAMESPACE_VERSION
60#if __cpp_lib_three_way_comparison
61 inline strong_ordering
62 operator<=>(thread::id __x, thread::id __y)
noexcept
63 {
return __x._M_thread <=> __y._M_thread; }
66 operator!=(thread::id __x, thread::id __y)
noexcept
67 {
return !(__x == __y); }
70 operator<(thread::id __x, thread::id __y)
noexcept
74 return __x._M_thread < __y._M_thread;
78 operator<=(thread::id __x, thread::id __y)
noexcept
79 {
return !(__y < __x); }
82 operator>(thread::id __x, thread::id __y)
noexcept
86 operator>=(thread::id __x, thread::id __y)
noexcept
87 {
return !(__x < __y); }
90 template<
class _CharT,
class _Traits>
91 inline basic_ostream<_CharT, _Traits>&
92 operator<<(basic_ostream<_CharT, _Traits>& __out, thread::id __id)
94 if (__id == thread::id())
95 return __out <<
"thread::id of a non-executing thread";
97 return __out << __id._M_thread;
100#ifdef __cpp_lib_jthread
102#ifndef __STRICT_ANSI__
103 template<
typename _Callable,
typename... _Args>
104 constexpr bool __pmf_expects_stop_token =
false;
106 template<
typename _Callable,
typename _Obj,
typename... _Args>
107 constexpr bool __pmf_expects_stop_token<_Callable, _Obj, _Args...>
108 = __and_<is_member_function_pointer<remove_reference_t<_Callable>>,
109 is_invocable<_Callable, _Obj, stop_token, _Args...>>::value;
117 using native_handle_type = thread::native_handle_type;
120 : _M_stop_source{nostopstate}
123 template<
typename _Callable,
typename... _Args,
127 jthread(_Callable&& __f, _Args&&... __args)
128 : _M_thread{_S_create(_M_stop_source, std::forward<_Callable>(__f),
129 std::forward<_Args>(__args)...)}
145 operator=(
const jthread&) =
delete;
148 operator=(
jthread&& __other)
noexcept
155 swap(
jthread& __other)
noexcept
157 std::swap(_M_stop_source, __other._M_stop_source);
162 joinable()
const noexcept
164 return _M_thread.joinable();
180 get_id()
const noexcept
182 return _M_thread.get_id();
185 [[nodiscard]] native_handle_type
191 [[nodiscard]]
static unsigned
192 hardware_concurrency()
noexcept
194 return thread::hardware_concurrency();
198 get_stop_source()
noexcept
200 return _M_stop_source;
204 get_stop_token()
const noexcept
206 return _M_stop_source.get_token();
209 bool request_stop()
noexcept
211 return _M_stop_source.request_stop();
220 template<
typename _Callable,
typename... _Args>
222 _S_create(
stop_source& __ssrc, _Callable&& __f, _Args&&... __args)
224#ifndef __STRICT_ANSI__
225 if constexpr (__pmf_expects_stop_token<_Callable, _Args...>)
226 return _S_create_pmf(__ssrc, __f, std::forward<_Args>(__args)...);
229 if constexpr(is_invocable_v<decay_t<_Callable>,
stop_token,
231 return thread{std::forward<_Callable>(__f), __ssrc.get_token(),
232 std::forward<_Args>(__args)...};
235 static_assert(is_invocable_v<decay_t<_Callable>,
237 "std::jthread arguments must be invocable after"
238 " conversion to rvalues");
239 return thread{std::forward<_Callable>(__f),
240 std::forward<_Args>(__args)...};
244#ifndef __STRICT_ANSI__
245 template<
typename _Callable,
typename _Obj,
typename... _Args>
247 _S_create_pmf(
stop_source& __ssrc, _Callable __f, _Obj&& __obj,
250 return thread{__f, std::forward<_Obj>(__obj), __ssrc.get_token(),
251 std::forward<_Args>(__args)...};
262_GLIBCXX_END_NAMESPACE_VERSION
typename decay< _Tp >::type decay_t
Alias template for decay.
typename enable_if< _Cond, _Tp >::type enable_if_t
Alias template for enable_if.
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
void swap(any &__x, any &__y) noexcept
Exchange the states of two any objects.
ISO C++ entities toplevel namespace is std.
std::basic_ostream< _CharT, _Traits > & operator<<(std::basic_ostream< _CharT, _Traits > &__os, const bitset< _Nb > &__x)
Global I/O operators for bitsets.
Allow testing whether a stop request has been made on a stop_source.
A type that allows a stop request to be made.
A thread that can be requested to stop and automatically joined.
native_handle_type native_handle()