85#ifdef _GLIBCXX_HAS_GTHREADS
86 using native_handle_type = __gthread_t;
88 using native_handle_type = int;
98 native_handle_type _M_thread;
101 id() noexcept : _M_thread() { }
104 id(native_handle_type __id) : _M_thread(__id) { }
111 operator==(
id __x,
id __y)
noexcept;
113#if __cpp_lib_three_way_comparison
114 friend strong_ordering
115 operator<=>(
id __x,
id __y)
noexcept;
118 operator<(
id __x,
id __y)
noexcept;
121 template<
class _CharT,
class _Traits>
125#if __glibcxx_formatters
126 friend formatter<id, char>;
127 friend formatter<id, wchar_t>;
137 template<
typename _Tp>
138 using __not_same = __not_<is_same<__remove_cvref_t<_Tp>,
thread>>;
141 thread() noexcept = default;
143#ifdef _GLIBCXX_HAS_GTHREADS
152 _M_thread_deps_never_run() {
153#ifdef GTHR_ACTIVE_PROXY
154 reinterpret_cast<void (*)(
void)
>(&pthread_create)();
155 reinterpret_cast<void (*)(
void)
>(&pthread_join)();
160 template<
typename _Callable,
typename... _Args,
161 typename = _Require<__not_same<_Callable>>>
163 thread(_Callable&& __f, _Args&&... __args)
165 static_assert( __is_invocable<typename decay<_Callable>::type,
166 typename decay<_Args>::type...>::value,
167 "std::thread arguments must be invocable after conversion to rvalues"
170 using _Wrapper = _Call_wrapper<_Callable, _Args...>;
173 _M_start_thread(_State_ptr(
new _State_impl<_Wrapper>(
175 _M_thread_deps_never_run);
185 thread(
const thread&) =
delete;
187 thread(thread&& __t)
noexcept
190 thread& operator=(
const thread&) =
delete;
192 thread& operator=(thread&& __t)
noexcept
201 swap(thread& __t)
noexcept
202 { std::swap(_M_id, __t._M_id); }
205 joinable() const noexcept
206 {
return !(_M_id == id()); }
215 get_id() const noexcept
222 {
return _M_id._M_thread; }
226 hardware_concurrency() noexcept;
228#ifdef _GLIBCXX_HAS_GTHREADS
229#ifndef _GLIBCXX_THREAD_IMPL
237 virtual void _M_run() = 0;
239 using _State_ptr = unique_ptr<_State>;
242 template<
typename _Callable>
243 struct _State_impl :
public _State
247 template<
typename... _Args>
248 _State_impl(_Args&&... __args)
253 _M_run() { _M_func(); }
257 _M_start_thread(_State_ptr,
void (*)());
259#if _GLIBCXX_THREAD_ABI_COMPAT
262 typedef shared_ptr<_Impl_base> __shared_base_type;
265 __shared_base_type _M_this_ptr;
266 virtual ~_Impl_base() =
default;
267 virtual void _M_run() = 0;
272 _M_start_thread(__shared_base_type,
void (*)());
275 _M_start_thread(__shared_base_type);
280 template<
typename _Tuple>
283 template<
typename... _Args>
285 _Invoker(_Args&&... __args)
293 template<
typename _Fn,
typename... _Args>
294 struct __result<tuple<_Fn, _Args...>>
295 : __invoke_result<_Fn, _Args...>
298 template<
size_t... _Ind>
299 typename __result<_Tuple>::type
300 _M_invoke(_Index_tuple<_Ind...>)
303 typename __result<_Tuple>::type
307 =
typename _Build_index_tuple<tuple_size<_Tuple>::value>::__type;
308 return _M_invoke(_Indices());
314 template<
typename... _Tp>
315 using _Call_wrapper = _Invoker<tuple<typename decay<_Tp>::type...>>;
constexpr __invoke_result< _Callable, _Args... >::type __invoke(_Callable &&__fn, _Args &&... __args) noexcept(__is_nothrow_invocable< _Callable, _Args... >::value)
Invoke a callable object.