30#ifndef _GLIBCXX_THREAD_H
31#define _GLIBCXX_THREAD_H 1
33#pragma GCC system_header
35#if __cplusplus >= 201103L
46#ifdef _GLIBCXX_HAS_GTHREADS
47# include <bits/gthr.h>
53namespace std _GLIBCXX_VISIBILITY(default)
55_GLIBCXX_BEGIN_NAMESPACE_VERSION
65#ifdef _GLIBCXX_HAS_GTHREADS
71 virtual void _M_run() = 0;
75 using native_handle_type = __gthread_t;
77 using native_handle_type = int;
83 native_handle_type _M_thread;
86 id() noexcept : _M_thread() { }
89 id(native_handle_type __id) : _M_thread(__id) { }
96 operator==(
id __x,
id __y)
noexcept;
98#if __cpp_lib_three_way_comparison
99 friend strong_ordering
100 operator<=>(
id __x,
id __y)
noexcept;
103 operator<(
id __x,
id __y)
noexcept;
106 template<
class _CharT,
class _Traits>
117 template<
typename _Tp>
118 using __not_same = __not_<is_same<__remove_cvref_t<_Tp>,
thread>>;
121 thread() noexcept = default;
123#ifdef _GLIBCXX_HAS_GTHREADS
124 template<
typename _Callable,
typename... _Args,
125 typename = _Require<__not_same<_Callable>>>
127 thread(_Callable&& __f, _Args&&... __args)
129 static_assert( __is_invocable<typename decay<_Callable>::type,
130 typename decay<_Args>::type...>::value,
131 "std::thread arguments must be invocable after conversion to rvalues"
134#ifdef GTHR_ACTIVE_PROXY
136 auto __depend =
reinterpret_cast<void(*)()
>(&pthread_create);
138 auto __depend =
nullptr;
140 using _Wrapper = _Call_wrapper<_Callable, _Args...>;
143 _M_start_thread(
_State_ptr(
new _State_impl<_Wrapper>(
144 std::forward<_Callable>(__f), std::forward<_Args>(__args)...)),
155 thread(
const thread&) =
delete;
157 thread(thread&& __t)
noexcept
160 thread& operator=(
const thread&) =
delete;
162 thread& operator=(thread&& __t)
noexcept
171 swap(thread& __t)
noexcept
175 joinable() const noexcept
176 {
return !(_M_id == id()); }
185 get_id() const noexcept
192 {
return _M_id._M_thread; }
196 hardware_concurrency() noexcept;
198#ifdef _GLIBCXX_HAS_GTHREADS
200 template<
typename _Callable>
201 struct _State_impl :
public _State
205 template<
typename... _Args>
206 _State_impl(_Args&&... __args)
211 _M_run() { _M_func(); }
215 _M_start_thread(_State_ptr,
void (*)());
217#if _GLIBCXX_THREAD_ABI_COMPAT
220 typedef shared_ptr<_Impl_base> __shared_base_type;
223 __shared_base_type _M_this_ptr;
224 virtual ~_Impl_base() =
default;
225 virtual void _M_run() = 0;
230 _M_start_thread(__shared_base_type,
void (*)());
233 _M_start_thread(__shared_base_type);
238 template<
typename _Tuple>
241 template<
typename... _Args>
243 _Invoker(_Args&&... __args)
251 template<
typename _Fn,
typename... _Args>
252 struct __result<tuple<_Fn, _Args...>>
253 : __invoke_result<_Fn, _Args...>
256 template<
size_t... _Ind>
257 typename __result<_Tuple>::type
258 _M_invoke(_Index_tuple<_Ind...>)
261 typename __result<_Tuple>::type
265 =
typename _Build_index_tuple<tuple_size<_Tuple>::value>::__type;
266 return _M_invoke(_Indices());
271 template<
typename... _Tp>
272 using _Call_wrapper = _Invoker<tuple<typename decay<_Tp>::type...>>;
276#ifndef _GLIBCXX_HAS_GTHREADS
277 inline void thread::join() { std::__throw_system_error(EINVAL); }
278 inline void thread::detach() { std::__throw_system_error(EINVAL); }
279 inline unsigned int thread::hardware_concurrency() noexcept {
return 0; }
283 swap(thread& __x, thread& __y)
noexcept
287 operator==(thread::id __x, thread::id __y)
noexcept
293 return __x._M_thread == __y._M_thread;
302 :
public __hash_base<size_t, thread::id>
305 operator()(
const thread::id& __id)
const noexcept
306 {
return std::_Hash_impl::hash(__id._M_thread); }
309 namespace this_thread
315#ifndef _GLIBCXX_HAS_GTHREADS
317#elif defined _GLIBCXX_NATIVE_THREAD_ID
328#if defined _GLIBCXX_HAS_GTHREADS && defined _GLIBCXX_USE_SCHED_YIELD
337_GLIBCXX_END_NAMESPACE_VERSION
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
constexpr __invoke_result< _Callable, _Args... >::type __invoke(_Callable &&__fn, _Args &&... __args) noexcept(__is_nothrow_invocable< _Callable, _Args... >::value)
Invoke a callable object.
void swap(any &__x, any &__y) noexcept
Exchange the states of two any objects.
constexpr _Tp && forward(typename std::remove_reference< _Tp >::type &__t) noexcept
Forward an lvalue.
void terminate() noexcept
ISO C++ entities toplevel namespace is std.
void yield() noexcept
this_thread::yield
thread::id get_id() noexcept
this_thread::get_id
Template class basic_ostream.
Primary class template hash.
native_handle_type native_handle()
20.7.1.2 unique_ptr for single objects.