87#ifdef _GLIBCXX_HAS_GTHREADS
88 using native_handle_type = __gthread_t;
90 using native_handle_type = int;
100 native_handle_type _M_thread;
103 id() noexcept : _M_thread() { }
106 id(native_handle_type __id) : _M_thread(__id) { }
110 friend struct hash<id>;
113 operator==(
id __x,
id __y)
noexcept;
115#if __cpp_lib_three_way_comparison
116 friend strong_ordering
117 operator<=>(
id __x,
id __y)
noexcept;
120 operator<(
id __x,
id __y)
noexcept;
123 template<
class _CharT,
class _Traits>
127#if __glibcxx_formatters
128 friend formatter<id, char>;
129 friend formatter<id, wchar_t>;
139 template<
typename _Tp>
140 using __not_same = __not_<is_same<__remove_cvref_t<_Tp>, thread>>;
143 thread() noexcept = default;
145#ifdef _GLIBCXX_HAS_GTHREADS
154 _M_thread_deps_never_run() {
155#ifdef GTHR_ACTIVE_PROXY
156 reinterpret_cast<void (*)(
void)
>(&pthread_create)();
157 reinterpret_cast<void (*)(
void)
>(&pthread_join)();
162 template<
typename _Callable,
typename... _Args,
163 typename = _Require<__not_same<_Callable>>>
165 thread(_Callable&& __f, _Args&&... __args)
167 static_assert( __is_invocable<typename decay<_Callable>::type,
168 typename decay<_Args>::type...>::value,
169 "std::thread arguments must be invocable after conversion to rvalues"
172 using _Wrapper = _Call_wrapper<_Callable, _Args...>;
175 _M_start_thread(_State_ptr(
new _State_impl<_Wrapper>(
177 _M_thread_deps_never_run);
187 thread(
const thread&) =
delete;
189 thread(thread&& __t)
noexcept
192 thread& operator=(
const thread&) =
delete;
194 thread& operator=(thread&& __t)
noexcept
203 swap(thread& __t)
noexcept
204 { std::swap(_M_id, __t._M_id); }
207 joinable() const noexcept
208 {
return !(_M_id ==
id()); }
217 get_id() const noexcept
224 {
return _M_id._M_thread; }
228 hardware_concurrency() noexcept;
230#ifdef _GLIBCXX_HAS_GTHREADS
231#ifndef _GLIBCXX_THREAD_IMPL
239 virtual void _M_run() = 0;
241 using _State_ptr = unique_ptr<_State>;
244 template<
typename _Callable>
245 struct _State_impl :
public _State
249 template<
typename... _Args>
250 _State_impl(_Args&&... __args)
255 _M_run() { _M_func(); }
259 _M_start_thread(_State_ptr,
void (*)());
261#if _GLIBCXX_THREAD_ABI_COMPAT
264 typedef shared_ptr<_Impl_base> __shared_base_type;
267 __shared_base_type _M_this_ptr;
268 virtual ~_Impl_base() =
default;
269 virtual void _M_run() = 0;
274 _M_start_thread(__shared_base_type,
void (*)());
277 _M_start_thread(__shared_base_type);
282 template<
typename _Tuple>
285 template<
typename... _Args>
287 _Invoker(_Args&&... __args)
288 : _M_t(std::
forward<_Args>(__args)...)
295 template<
typename _Fn,
typename... _Args>
296 struct __result<tuple<_Fn, _Args...>>
297 : __invoke_result<_Fn, _Args...>
300 template<
size_t... _Ind>
301 typename __result<_Tuple>::type
302 _M_invoke(_Index_tuple<_Ind...>)
305 typename __result<_Tuple>::type
309 =
typename _Build_index_tuple<tuple_size<_Tuple>::value>::__type;
310 return _M_invoke(_Indices());
316 template<
typename... _Tp>
317 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.