30#ifndef _GLIBCXX_THREAD_H
31#define _GLIBCXX_THREAD_H 1
33#pragma GCC system_header
35#if __cplusplus >= 201103L
45#ifdef _GLIBCXX_HAS_GTHREADS
46# include <bits/gthr.h>
52namespace std _GLIBCXX_VISIBILITY(default)
54_GLIBCXX_BEGIN_NAMESPACE_VERSION
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
135 template<
typename _Callable,
typename... _Args,
136 typename = _Require<__not_same<_Callable>>>
138 thread(_Callable&& __f, _Args&&... __args)
140 static_assert( __is_invocable<typename decay<_Callable>::type,
141 typename decay<_Args>::type...>::value,
142 "std::thread arguments must be invocable after conversion to rvalues"
145#ifdef GTHR_ACTIVE_PROXY
147 auto __depend =
reinterpret_cast<void(*)()
>(&pthread_create);
149 auto __depend =
nullptr;
151 using _Wrapper = _Call_wrapper<_Callable, _Args...>;
154 _M_start_thread(
_State_ptr(
new _State_impl<_Wrapper>(
155 std::forward<_Callable>(__f), std::forward<_Args>(__args)...)),
166 thread(
const thread&) =
delete;
168 thread(thread&& __t)
noexcept
171 thread& operator=(
const thread&) =
delete;
173 thread& operator=(thread&& __t)
noexcept
182 swap(thread& __t)
noexcept
186 joinable() const noexcept
187 {
return !(_M_id == id()); }
203 {
return _M_id._M_thread; }
207 hardware_concurrency() noexcept;
209#ifdef _GLIBCXX_HAS_GTHREADS
210#ifndef _GLIBCXX_THREAD_IMPL
218 virtual void _M_run() = 0;
220 using _State_ptr = unique_ptr<_State>;
223 template<
typename _Callable>
224 struct _State_impl :
public _State
228 template<
typename... _Args>
229 _State_impl(_Args&&... __args)
234 _M_run() { _M_func(); }
238 _M_start_thread(_State_ptr,
void (*)());
240#if _GLIBCXX_THREAD_ABI_COMPAT
243 typedef shared_ptr<_Impl_base> __shared_base_type;
246 __shared_base_type _M_this_ptr;
247 virtual ~_Impl_base() =
default;
248 virtual void _M_run() = 0;
253 _M_start_thread(__shared_base_type,
void (*)());
256 _M_start_thread(__shared_base_type);
261 template<
typename _Tuple>
264 template<
typename... _Args>
266 _Invoker(_Args&&... __args)
274 template<
typename _Fn,
typename... _Args>
275 struct __result<tuple<_Fn, _Args...>>
276 : __invoke_result<_Fn, _Args...>
279 template<
size_t... _Ind>
280 typename __result<_Tuple>::type
281 _M_invoke(_Index_tuple<_Ind...>)
284 typename __result<_Tuple>::type
288 =
typename _Build_index_tuple<tuple_size<_Tuple>::value>::__type;
289 return _M_invoke(_Indices());
295 template<
typename... _Tp>
296 using _Call_wrapper = _Invoker<tuple<typename decay<_Tp>::type...>>;
301#ifndef _GLIBCXX_HAS_GTHREADS
302 inline void thread::join() { std::__throw_system_error(EINVAL); }
303 inline void thread::detach() { std::__throw_system_error(EINVAL); }
304 inline unsigned int thread::hardware_concurrency() noexcept {
return 0; }
309 swap(thread& __x, thread& __y)
noexcept
314 operator==(thread::id __x, thread::id __y)
noexcept
320 return __x._M_thread == __y._M_thread;
329 :
public __hash_base<size_t, thread::id>
332 operator()(
const thread::id& __id)
const noexcept
333 {
return std::_Hash_impl::hash(__id._M_thread); }
336 namespace this_thread
342#ifndef _GLIBCXX_HAS_GTHREADS
344#elif defined _GLIBCXX_NATIVE_THREAD_ID
355#if defined _GLIBCXX_HAS_GTHREADS && defined _GLIBCXX_USE_SCHED_YIELD
364_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.
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.
void yield() noexcept
Allow the implementation to schedule a different thread.
thread::id get_id() noexcept
The unique identifier of the current thread.
Template class basic_ostream.
Primary class template hash.
native_handle_type native_handle()
A move-only smart pointer that manages unique ownership of a resource.