29 #ifndef _GLIBCXX_THREAD
30 #define _GLIBCXX_THREAD 1
32 #pragma GCC system_header
34 #if __cplusplus < 201103L
38 #if __cplusplus > 201703L
46 namespace std _GLIBCXX_VISIBILITY(default)
48 _GLIBCXX_BEGIN_NAMESPACE_VERSION
63 #if __cpp_lib_three_way_comparison
64 inline strong_ordering
65 operator<=>(thread::id __x, thread::id __y) noexcept
66 {
return __x._M_thread <=> __y._M_thread; }
69 operator!=(thread::id __x, thread::id __y) noexcept
70 {
return !(__x == __y); }
73 operator<(thread::id __x, thread::id __y) noexcept
77 return __x._M_thread < __y._M_thread;
81 operator<=(thread::id __x, thread::id __y) noexcept
82 {
return !(__y < __x); }
85 operator>(thread::id __x, thread::id __y) noexcept
89 operator>=(thread::id __x, thread::id __y) noexcept
90 {
return !(__x < __y); }
93 template<
class _CharT,
class _Traits>
94 inline basic_ostream<_CharT, _Traits>&
95 operator<<(basic_ostream<_CharT, _Traits>& __out, thread::id __id)
97 if (__id == thread::id())
98 return __out <<
"thread::id of a non-executing thread";
100 return __out << __id._M_thread;
104 #ifdef __cpp_lib_jthread
107 #ifndef __STRICT_ANSI__
108 template<
typename _Callable,
typename... _Args>
109 constexpr
bool __pmf_expects_stop_token =
false;
111 template<
typename _Callable,
typename _Obj,
typename... _Args>
112 constexpr
bool __pmf_expects_stop_token<_Callable, _Obj, _Args...>
113 = __and_<is_member_function_pointer<remove_reference_t<_Callable>>,
114 is_invocable<_Callable, _Obj, stop_token, _Args...>>::value;
136 using native_handle_type = thread::native_handle_type;
139 : _M_stop_source{nostopstate}
142 template<
typename _Callable,
typename... _Args,
146 jthread(_Callable&& __f, _Args&&... __args)
147 : _M_thread{_S_create(_M_stop_source, std::forward<_Callable>(__f),
148 std::forward<_Args>(__args)...)}
164 operator=(
const jthread&) =
delete;
167 operator=(
jthread&& __other) noexcept
174 swap(
jthread& __other) noexcept
176 std::swap(_M_stop_source, __other._M_stop_source);
181 joinable()
const noexcept
183 return _M_thread.joinable();
199 get_id()
const noexcept
201 return _M_thread.get_id();
204 [[nodiscard]] native_handle_type
210 [[nodiscard]]
static unsigned
211 hardware_concurrency() noexcept
213 return thread::hardware_concurrency();
217 get_stop_source() noexcept
219 return _M_stop_source;
223 get_stop_token()
const noexcept
225 return _M_stop_source.get_token();
228 bool request_stop() noexcept
230 return _M_stop_source.request_stop();
239 template<
typename _Callable,
typename... _Args>
241 _S_create(
stop_source& __ssrc, _Callable&& __f, _Args&&... __args)
243 #ifndef __STRICT_ANSI__
244 if constexpr (__pmf_expects_stop_token<_Callable, _Args...>)
245 return _S_create_pmf(__ssrc, __f, std::forward<_Args>(__args)...);
250 return thread{std::forward<_Callable>(__f), __ssrc.get_token(),
251 std::forward<_Args>(__args)...};
256 "std::jthread arguments must be invocable after"
257 " conversion to rvalues");
258 return thread{std::forward<_Callable>(__f),
259 std::forward<_Args>(__args)...};
263 #ifndef __STRICT_ANSI__
264 template<
typename _Callable,
typename _Obj,
typename... _Args>
266 _S_create_pmf(
stop_source& __ssrc, _Callable __f, _Obj&& __obj,
269 return thread{__f, std::forward<_Obj>(__obj), __ssrc.get_token(),
270 std::forward<_Args>(__args)...};
281 _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.
native_handle_type native_handle()