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>
52 namespace std _GLIBCXX_VISIBILITY(default)
54 _GLIBCXX_BEGIN_NAMESPACE_VERSION
64 #ifdef _GLIBCXX_HAS_GTHREADS
70 virtual void _M_run() = 0;
74 using native_handle_type = __gthread_t;
76 using native_handle_type = int;
82 native_handle_type _M_thread;
85 id() noexcept : _M_thread() { }
88 id(native_handle_type __id) : _M_thread(__id) { }
95 operator==(
id __x,
id __y) noexcept;
97 #if __cpp_lib_three_way_comparison
98 friend strong_ordering
99 operator<=>(
id __x,
id __y) noexcept;
102 operator<(
id __x,
id __y) noexcept;
105 template<
class _CharT,
class _Traits>
116 template<
typename _Tp>
117 using __not_same = __not_<is_same<__remove_cvref_t<_Tp>,
thread>>;
120 thread() noexcept = default;
122 #ifdef _GLIBCXX_HAS_GTHREADS
123 template<
typename _Callable,
typename... _Args,
124 typename = _Require<__not_same<_Callable>>>
126 thread(_Callable&& __f, _Args&&... __args)
128 static_assert( __is_invocable<
typename decay<_Callable>::type,
129 typename decay<_Args>::type...>::value,
130 "std::thread arguments must be invocable after conversion to rvalues"
133 #ifdef GTHR_ACTIVE_PROXY
135 auto __depend =
reinterpret_cast<void(*)()
>(&pthread_create);
137 auto __depend =
nullptr;
139 using _Wrapper = _Call_wrapper<_Callable, _Args...>;
142 _M_start_thread(
_State_ptr(
new _State_impl<_Wrapper>(
143 std::forward<_Callable>(__f), std::forward<_Args>(__args)...)),
154 thread(
const thread&) =
delete;
156 thread(thread&& __t) noexcept
159 thread& operator=(
const thread&) =
delete;
161 thread& operator=(thread&& __t) noexcept
170 swap(thread& __t) noexcept
174 joinable() const noexcept
175 {
return !(_M_id == id()); }
191 {
return _M_id._M_thread; }
195 hardware_concurrency() noexcept;
197 #ifdef _GLIBCXX_HAS_GTHREADS
199 template<
typename _Callable>
200 struct _State_impl :
public _State
204 template<
typename... _Args>
205 _State_impl(_Args&&... __args)
206 : _M_func{{std::forward<_Args>(__args)...}}
210 _M_run() { _M_func(); }
214 _M_start_thread(_State_ptr,
void (*)());
216 #if _GLIBCXX_THREAD_ABI_COMPAT
219 typedef shared_ptr<_Impl_base> __shared_base_type;
222 __shared_base_type _M_this_ptr;
223 virtual ~_Impl_base() =
default;
224 virtual void _M_run() = 0;
229 _M_start_thread(__shared_base_type,
void (*)());
232 _M_start_thread(__shared_base_type);
237 template<
typename _Tuple>
244 template<
typename _Fn,
typename... _Args>
245 struct __result<tuple<_Fn, _Args...>>
246 : __invoke_result<_Fn, _Args...>
249 template<
size_t... _Ind>
250 typename __result<_Tuple>::type
251 _M_invoke(_Index_tuple<_Ind...>)
254 typename __result<_Tuple>::type
258 =
typename _Build_index_tuple<tuple_size<_Tuple>::value>::__type;
259 return _M_invoke(_Indices());
264 template<
typename... _Tp>
265 using _Call_wrapper = _Invoker<tuple<typename decay<_Tp>::type...>>;
269 #ifndef _GLIBCXX_HAS_GTHREADS
270 inline void thread::join() { std::__throw_system_error(EINVAL); }
271 inline void thread::detach() { std::__throw_system_error(EINVAL); }
272 inline unsigned int thread::hardware_concurrency() noexcept {
return 0; }
276 swap(thread& __x, thread& __y) noexcept
280 operator==(thread::id __x, thread::id __y) noexcept
286 return __x._M_thread == __y._M_thread;
295 :
public __hash_base<size_t, thread::id>
298 operator()(
const thread::id& __id)
const noexcept
299 {
return std::_Hash_impl::hash(__id._M_thread); }
302 namespace this_thread
308 #ifndef _GLIBCXX_HAS_GTHREADS
310 #elif defined _GLIBCXX_NATIVE_THREAD_ID
321 #if defined _GLIBCXX_HAS_GTHREADS && defined _GLIBCXX_USE_SCHED_YIELD
330 _GLIBCXX_END_NAMESPACE_VERSION
constexpr bool operator==(const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)
constexpr __invoke_result< _Callable, _Args... >::type __invoke(_Callable &&__fn, _Args &&... __args) noexcept(__is_nothrow_invocable< _Callable, _Args... >::value)
Invoke a callable object.
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
void swap(any &__x, any &__y) noexcept
Exchange the states of two any objects.
void swap(shared_lock< _Mutex > &__x, shared_lock< _Mutex > &__y) noexcept
Swap specialization for shared_lock.
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
this_thread::yield
thread::id get_id() noexcept
this_thread::get_id
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.