29 #ifndef _GLIBCXX_THREAD
30 #define _GLIBCXX_THREAD 1
32 #pragma GCC system_header
34 #if __cplusplus < 201103L
40 #if __cplusplus > 201703L
47 #ifdef _GLIBCXX_USE_NANOSLEEP
52 namespace std _GLIBCXX_VISIBILITY(default)
54 _GLIBCXX_BEGIN_NAMESPACE_VERSION
66 #if __cpp_lib_three_way_comparison
67 inline strong_ordering
68 operator<=>(thread::id __x, thread::id __y) noexcept
69 {
return __x._M_thread <=> __y._M_thread; }
72 operator!=(thread::id __x, thread::id __y) noexcept
73 {
return !(__x == __y); }
76 operator<(thread::id __x, thread::id __y) noexcept
80 return __x._M_thread < __y._M_thread;
84 operator<=(thread::id __x, thread::id __y) noexcept
85 {
return !(__y < __x); }
88 operator>(thread::id __x, thread::id __y) noexcept
92 operator>=(thread::id __x, thread::id __y) noexcept
93 {
return !(__x < __y); }
96 template<
class _CharT,
class _Traits>
97 inline basic_ostream<_CharT, _Traits>&
98 operator<<(basic_ostream<_CharT, _Traits>& __out, thread::id __id)
100 if (__id == thread::id())
101 return __out <<
"thread::id of a non-executing thread";
103 return __out << __id._M_thread;
111 namespace this_thread
113 #ifndef _GLIBCXX_NO_SLEEP
115 #ifndef _GLIBCXX_USE_NANOSLEEP
121 template<
typename _Rep,
typename _Period>
125 if (__rtime <= __rtime.zero())
127 auto __s = chrono::duration_cast<chrono::seconds>(__rtime);
128 auto __ns = chrono::duration_cast<chrono::nanoseconds>(__rtime - __s);
129 #ifdef _GLIBCXX_USE_NANOSLEEP
130 struct ::timespec __ts =
132 static_cast<std::time_t
>(__s.count()),
133 static_cast<long>(__ns.count())
135 while (::nanosleep(&__ts, &__ts) == -1 && errno == EINTR)
138 __sleep_for(__s, __ns);
143 template<
typename _Clock,
typename _Duration>
147 #if __cplusplus > 201703L
148 static_assert(chrono::is_clock_v<_Clock>);
150 auto __now = _Clock::now();
151 if (_Clock::is_steady)
157 while (__now < __atime)
160 __now = _Clock::now();
166 #ifdef __cpp_lib_jthread
172 using id = thread::id;
173 using native_handle_type = thread::native_handle_type;
176 : _M_stop_source{nostopstate}
179 template<
typename _Callable,
typename... _Args,
180 typename = enable_if_t<!is_same_v<remove_cvref_t<_Callable>,
183 jthread(_Callable&& __f, _Args&&... __args)
184 : _M_thread{_S_create(_M_stop_source,
std::
forward<_Callable>(__f),
188 jthread(
const jthread&) =
delete;
189 jthread(jthread&&) noexcept = default;
206 std::jthread(
std::move(__other)).swap(*
this);
211 swap(jthread& __other) noexcept
213 std::swap(_M_stop_source, __other._M_stop_source);
218 joinable() const noexcept
220 return _M_thread.joinable();
238 return _M_thread.get_id();
241 [[nodiscard]] native_handle_type
244 return _M_thread.native_handle();
247 [[nodiscard]]
static unsigned
248 hardware_concurrency() noexcept
250 return thread::hardware_concurrency();
253 [[nodiscard]] stop_source
254 get_stop_source() noexcept
256 return _M_stop_source;
259 [[nodiscard]] stop_token
260 get_stop_token() const noexcept
262 return _M_stop_source.get_token();
265 bool request_stop() noexcept
267 return _M_stop_source.request_stop();
270 friend void swap(jthread& __lhs, jthread& __rhs) noexcept
276 template<
typename _Callable,
typename... _Args>
278 _S_create(stop_source& __ssrc, _Callable&& __f, _Args&&... __args)
282 return thread{std::forward<_Callable>(__f), __ssrc.get_token(),
283 std::forward<_Args>(__args)...};
288 "std::thread arguments must be invocable after"
289 " conversion to rvalues");
290 return thread{std::forward<_Callable>(__f),
291 std::forward<_Args>(__args)...};
295 stop_source _M_stop_source;
302 _GLIBCXX_END_NAMESPACE_VERSION
auto_ptr & operator=(auto_ptr &__a)
auto_ptr assignment operator.
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
constexpr _Tp && forward(typename std::remove_reference< _Tp >::type &__t) noexcept
Forward an lvalue.
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.
constexpr bool is_invocable_v
std::is_invocable_v
void sleep_until(const chrono::time_point< _Clock, _Duration > &__atime)
this_thread::sleep_until
void sleep_for(const chrono::duration< _Rep, _Period > &__rtime)
this_thread::sleep_for
thread::id get_id() noexcept
this_thread::get_id