81#ifdef _GLIBCXX_HAS_GTHREADS
82 using native_handle_type = __gthread_t;
84 using native_handle_type = int;
94 native_handle_type _M_thread;
97 id() noexcept : _M_thread() { }
100 id(native_handle_type __id) : _M_thread(__id) { }
107 operator==(
id __x,
id __y)
noexcept;
109#if __cpp_lib_three_way_comparison
110 friend strong_ordering
111 operator<=>(
id __x,
id __y)
noexcept;
114 operator<(
id __x,
id __y)
noexcept;
117 template<
class _CharT,
class _Traits>
128 template<
typename _Tp>
129 using __not_same = __not_<is_same<__remove_cvref_t<_Tp>,
thread>>;
132 thread() noexcept = default;
134#ifdef _GLIBCXX_HAS_GTHREADS
143 _M_thread_deps_never_run() {
144#ifdef GTHR_ACTIVE_PROXY
145 reinterpret_cast<void (*)(
void)
>(&pthread_create)();
146 reinterpret_cast<void (*)(
void)
>(&pthread_join)();
151 template<
typename _Callable,
typename... _Args,
152 typename = _Require<__not_same<_Callable>>>
154 thread(_Callable&& __f, _Args&&... __args)
156 static_assert( __is_invocable<typename decay<_Callable>::type,
157 typename decay<_Args>::type...>::value,
158 "std::thread arguments must be invocable after conversion to rvalues"
161 using _Wrapper = _Call_wrapper<_Callable, _Args...>;
164 _M_start_thread(_State_ptr(
new _State_impl<_Wrapper>(
165 std::forward<_Callable>(__f), std::forward<_Args>(__args)...)),
166 _M_thread_deps_never_run);
176 thread(
const thread&) =
delete;
178 thread(thread&& __t)
noexcept
181 thread& operator=(
const thread&) =
delete;
183 thread& operator=(thread&& __t)
noexcept
192 swap(thread& __t)
noexcept
193 { std::swap(_M_id, __t._M_id); }
196 joinable() const noexcept
197 {
return !(_M_id == id()); }
206 get_id() const noexcept
213 {
return _M_id._M_thread; }
217 hardware_concurrency() noexcept;
219#ifdef _GLIBCXX_HAS_GTHREADS
220#ifndef _GLIBCXX_THREAD_IMPL
228 virtual void _M_run() = 0;
230 using _State_ptr = unique_ptr<_State>;
233 template<
typename _Callable>
234 struct _State_impl :
public _State
238 template<
typename... _Args>
239 _State_impl(_Args&&... __args)
244 _M_run() { _M_func(); }
248 _M_start_thread(_State_ptr,
void (*)());
250#if _GLIBCXX_THREAD_ABI_COMPAT
253 typedef shared_ptr<_Impl_base> __shared_base_type;
256 __shared_base_type _M_this_ptr;
257 virtual ~_Impl_base() =
default;
258 virtual void _M_run() = 0;
263 _M_start_thread(__shared_base_type,
void (*)());
266 _M_start_thread(__shared_base_type);
271 template<
typename _Tuple>
274 template<
typename... _Args>
276 _Invoker(_Args&&... __args)
284 template<
typename _Fn,
typename... _Args>
285 struct __result<tuple<_Fn, _Args...>>
286 : __invoke_result<_Fn, _Args...>
289 template<
size_t... _Ind>
290 typename __result<_Tuple>::type
291 _M_invoke(_Index_tuple<_Ind...>)
294 typename __result<_Tuple>::type
298 =
typename _Build_index_tuple<tuple_size<_Tuple>::value>::__type;
299 return _M_invoke(_Indices());
305 template<
typename... _Tp>
306 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.