29 #ifndef _GLIBCXX_THREAD
30 #define _GLIBCXX_THREAD 1
32 #pragma GCC system_header
34 #if __cplusplus < 201103L
38 #if __cplusplus > 201703L
44 #include <bits/this_thread_sleep.h>
46 namespace 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); }
88 #endif // __cpp_lib_three_way_comparison
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
106 using id = thread::id;
107 using native_handle_type = thread::native_handle_type;
110 : _M_stop_source{nostopstate}
113 template<
typename _Callable,
typename... _Args,
114 typename = enable_if_t<!is_same_v<remove_cvref_t<_Callable>,
117 jthread(_Callable&& __f, _Args&&... __args)
118 : _M_thread{_S_create(_M_stop_source, std::forward<_Callable>(__f),
119 std::forward<_Args>(__args)...)}
122 jthread(
const jthread&) =
delete;
123 jthread(jthread&&) noexcept = default;
140 std::jthread(
std::move(__other)).swap(*
this);
145 swap(jthread& __other) noexcept
147 std::swap(_M_stop_source, __other._M_stop_source);
148 std::swap(_M_thread, __other._M_thread);
152 joinable() const noexcept
154 return _M_thread.joinable();
172 return _M_thread.get_id();
175 [[nodiscard]] native_handle_type
178 return _M_thread.native_handle();
181 [[nodiscard]]
static unsigned
182 hardware_concurrency() noexcept
184 return thread::hardware_concurrency();
187 [[nodiscard]] stop_source
188 get_stop_source() noexcept
190 return _M_stop_source;
193 [[nodiscard]] stop_token
194 get_stop_token() const noexcept
196 return _M_stop_source.get_token();
199 bool request_stop() noexcept
201 return _M_stop_source.request_stop();
204 friend void swap(jthread& __lhs, jthread& __rhs) noexcept
210 template<
typename _Callable,
typename... _Args>
212 _S_create(stop_source& __ssrc, _Callable&& __f, _Args&&... __args)
216 return thread{std::forward<_Callable>(__f), __ssrc.get_token(),
217 std::forward<_Args>(__args)...};
222 "std::thread arguments must be invocable after"
223 " conversion to rvalues");
224 return thread{std::forward<_Callable>(__f),
225 std::forward<_Args>(__args)...};
229 stop_source _M_stop_source;
232 #endif // __cpp_lib_jthread
236 _GLIBCXX_END_NAMESPACE_VERSION
239 #endif // _GLIBCXX_THREAD
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
thread::id get_id() noexcept
this_thread::get_id
constexpr bool is_invocable_v
std::is_invocable_v
auto_ptr & operator=(auto_ptr &__a)
auto_ptr assignment operator.