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
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
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...>>;
311#ifndef _GLIBCXX_HAS_GTHREADS
312 inline void thread::join() { std::__throw_system_error(EINVAL); }
313 inline void thread::detach() { std::__throw_system_error(EINVAL); }
314 inline unsigned int thread::hardware_concurrency() noexcept {
return 0; }
319 swap(thread& __x, thread& __y)
noexcept
324 operator==(thread::id __x, thread::id __y)
noexcept
330 return __x._M_thread == __y._M_thread;
339 :
public __hash_base<size_t, thread::id>
342 operator()(
const thread::id& __id)
const noexcept
343 {
return std::_Hash_impl::hash(__id._M_thread); }
346 namespace this_thread
352#ifndef _GLIBCXX_HAS_GTHREADS
354#elif defined _GLIBCXX_NATIVE_THREAD_ID
365#if defined _GLIBCXX_HAS_GTHREADS && defined _GLIBCXX_USE_SCHED_YIELD
374_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()