29#ifndef _GLIBCXX_THREAD
30#define _GLIBCXX_THREAD 1
32#pragma GCC system_header
36#if __cplusplus < 201103L
40#if __cplusplus > 201703L
48namespace std _GLIBCXX_VISIBILITY(default)
50_GLIBCXX_BEGIN_NAMESPACE_VERSION
65#if __cpp_lib_three_way_comparison
66 inline strong_ordering
67 operator<=>(thread::id __x, thread::id __y)
noexcept
68 {
return __x._M_thread <=> __y._M_thread; }
71 operator!=(thread::id __x, thread::id __y)
noexcept
72 {
return !(__x == __y); }
75 operator<(thread::id __x, thread::id __y)
noexcept
79 return __x._M_thread < __y._M_thread;
83 operator<=(thread::id __x, thread::id __y)
noexcept
84 {
return !(__y < __x); }
87 operator>(thread::id __x, thread::id __y)
noexcept
91 operator>=(thread::id __x, thread::id __y)
noexcept
92 {
return !(__x < __y); }
95 template<
class _CharT,
class _Traits>
96 inline basic_ostream<_CharT, _Traits>&
97 operator<<(basic_ostream<_CharT, _Traits>& __out, thread::id __id)
99 if (__id == thread::id())
100 return __out <<
"thread::id of a non-executing thread";
102 return __out << __id._M_thread;
106#ifdef __cpp_lib_jthread
109#ifndef __STRICT_ANSI__
110 template<
typename _Callable,
typename... _Args>
111 constexpr bool __pmf_expects_stop_token =
false;
113 template<
typename _Callable,
typename _Obj,
typename... _Args>
114 constexpr bool __pmf_expects_stop_token<_Callable, _Obj, _Args...>
115 = __and_<is_member_function_pointer<remove_reference_t<_Callable>>,
116 is_invocable<_Callable, _Obj, stop_token, _Args...>>::value;
138 using native_handle_type = thread::native_handle_type;
141 : _M_stop_source{nostopstate}
144 template<
typename _Callable,
typename... _Args,
148 jthread(_Callable&& __f, _Args&&... __args)
149 : _M_thread{_S_create(_M_stop_source, std::forward<_Callable>(__f),
150 std::forward<_Args>(__args)...)}
166 operator=(
const jthread&) =
delete;
169 operator=(
jthread&& __other)
noexcept
176 swap(
jthread& __other)
noexcept
178 std::swap(_M_stop_source, __other._M_stop_source);
183 joinable()
const noexcept
185 return _M_thread.joinable();
201 get_id()
const noexcept
203 return _M_thread.get_id();
206 [[nodiscard]] native_handle_type
212 [[nodiscard]]
static unsigned
213 hardware_concurrency()
noexcept
215 return thread::hardware_concurrency();
219 get_stop_source()
noexcept
221 return _M_stop_source;
225 get_stop_token()
const noexcept
227 return _M_stop_source.get_token();
230 bool request_stop()
noexcept
232 return _M_stop_source.request_stop();
241 template<
typename _Callable,
typename... _Args>
243 _S_create(
stop_source& __ssrc, _Callable&& __f, _Args&&... __args)
245#ifndef __STRICT_ANSI__
246 if constexpr (__pmf_expects_stop_token<_Callable, _Args...>)
247 return _S_create_pmf(__ssrc, __f, std::forward<_Args>(__args)...);
250 if constexpr(is_invocable_v<decay_t<_Callable>,
stop_token,
252 return thread{std::forward<_Callable>(__f), __ssrc.get_token(),
253 std::forward<_Args>(__args)...};
256 static_assert(is_invocable_v<decay_t<_Callable>,
258 "std::jthread arguments must be invocable after"
259 " conversion to rvalues");
260 return thread{std::forward<_Callable>(__f),
261 std::forward<_Args>(__args)...};
265#ifndef __STRICT_ANSI__
266 template<
typename _Callable,
typename _Obj,
typename... _Args>
268 _S_create_pmf(
stop_source& __ssrc, _Callable __f, _Obj&& __obj,
271 return thread{__f, std::forward<_Obj>(__obj), __ssrc.get_token(),
272 std::forward<_Args>(__args)...};
283_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()