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
87 virtual void _M_run() = 0;
91 using native_handle_type = __gthread_t;
93 using native_handle_type = int;
103 native_handle_type _M_thread;
106 id() noexcept : _M_thread() { }
109 id(native_handle_type __id) : _M_thread(__id) { }
116 operator==(
id __x,
id __y)
noexcept;
118#if __cpp_lib_three_way_comparison
119 friend strong_ordering
120 operator<=>(
id __x,
id __y)
noexcept;
123 operator<(
id __x,
id __y)
noexcept;
126 template<
class _CharT,
class _Traits>
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
144 template<
typename _Callable,
typename... _Args,
145 typename = _Require<__not_same<_Callable>>>
147 thread(_Callable&& __f, _Args&&... __args)
149 static_assert( __is_invocable<typename decay<_Callable>::type,
150 typename decay<_Args>::type...>::value,
151 "std::thread arguments must be invocable after conversion to rvalues"
154#ifdef GTHR_ACTIVE_PROXY
156 auto __depend =
reinterpret_cast<void(*)()
>(&pthread_create);
158 auto __depend =
nullptr;
160 using _Wrapper = _Call_wrapper<_Callable, _Args...>;
163 _M_start_thread(
_State_ptr(
new _State_impl<_Wrapper>(
164 std::forward<_Callable>(__f), std::forward<_Args>(__args)...)),
175 thread(
const thread&) =
delete;
177 thread(thread&& __t)
noexcept
180 thread& operator=(
const thread&) =
delete;
182 thread& operator=(thread&& __t)
noexcept
191 swap(thread& __t)
noexcept
195 joinable() const noexcept
196 {
return !(_M_id == id()); }
205 get_id() const noexcept
212 {
return _M_id._M_thread; }
216 hardware_concurrency() noexcept;
218#ifdef _GLIBCXX_HAS_GTHREADS
220 template<
typename _Callable>
221 struct _State_impl :
public _State
225 template<
typename... _Args>
226 _State_impl(_Args&&... __args)
231 _M_run() { _M_func(); }
235 _M_start_thread(_State_ptr,
void (*)());
237#if _GLIBCXX_THREAD_ABI_COMPAT
240 typedef shared_ptr<_Impl_base> __shared_base_type;
243 __shared_base_type _M_this_ptr;
244 virtual ~_Impl_base() =
default;
245 virtual void _M_run() = 0;
250 _M_start_thread(__shared_base_type,
void (*)());
253 _M_start_thread(__shared_base_type);
258 template<
typename _Tuple>
261 template<
typename... _Args>
263 _Invoker(_Args&&... __args)
271 template<
typename _Fn,
typename... _Args>
272 struct __result<tuple<_Fn, _Args...>>
273 : __invoke_result<_Fn, _Args...>
276 template<
size_t... _Ind>
277 typename __result<_Tuple>::type
278 _M_invoke(_Index_tuple<_Ind...>)
281 typename __result<_Tuple>::type
285 =
typename _Build_index_tuple<tuple_size<_Tuple>::value>::__type;
286 return _M_invoke(_Indices());
292 template<
typename... _Tp>
293 using _Call_wrapper = _Invoker<tuple<typename decay<_Tp>::type...>>;
298#ifndef _GLIBCXX_HAS_GTHREADS
299 inline void thread::join() { std::__throw_system_error(EINVAL); }
300 inline void thread::detach() { std::__throw_system_error(EINVAL); }
301 inline unsigned int thread::hardware_concurrency() noexcept {
return 0; }
306 swap(thread& __x, thread& __y)
noexcept
311 operator==(thread::id __x, thread::id __y)
noexcept
317 return __x._M_thread == __y._M_thread;
326 :
public __hash_base<size_t, thread::id>
329 operator()(
const thread::id& __id)
const noexcept
330 {
return std::_Hash_impl::hash(__id._M_thread); }
333 namespace this_thread
339#ifndef _GLIBCXX_HAS_GTHREADS
341#elif defined _GLIBCXX_NATIVE_THREAD_ID
352#if defined _GLIBCXX_HAS_GTHREADS && defined _GLIBCXX_USE_SCHED_YIELD
361_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.
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.