30 #ifndef _GLIBCXX_THREAD_H
31 #define _GLIBCXX_THREAD_H 1
33 #pragma GCC system_header
35 #if __cplusplus >= 201103L
46 #ifdef _GLIBCXX_HAS_GTHREADS
47 # include <bits/gthr.h>
53 namespace std _GLIBCXX_VISIBILITY(default)
55 _GLIBCXX_BEGIN_NAMESPACE_VERSION
65 #ifdef _GLIBCXX_HAS_GTHREADS
71 virtual void _M_run() = 0;
75 using native_handle_type = __gthread_t;
77 using native_handle_type = int;
83 native_handle_type _M_thread;
86 id() noexcept : _M_thread() { }
89 id(native_handle_type __id) : _M_thread(__id) { }
93 friend struct hash<id>;
96 operator==(
id __x,
id __y) noexcept;
98 #if __cpp_lib_three_way_comparison
99 friend strong_ordering
100 operator<=>(
id __x,
id __y) noexcept;
103 operator<(
id __x,
id __y) noexcept;
106 template<
class _CharT,
class _Traits>
108 operator<<(basic_ostream<_CharT, _Traits>& __out,
id __id);
117 template<
typename _Tp>
118 using __not_same = __not_<is_same<__remove_cvref_t<_Tp>,
thread>>;
121 thread() noexcept = default;
123 #ifdef _GLIBCXX_HAS_GTHREADS
124 template<
typename _Callable,
typename... _Args,
125 typename = _Require<__not_same<_Callable>>>
127 thread(_Callable&& __f, _Args&&... __args)
129 static_assert( __is_invocable<
typename decay<_Callable>::type,
130 typename decay<_Args>::type...>::value,
131 "std::thread arguments must be invocable after conversion to rvalues"
134 #ifdef GTHR_ACTIVE_PROXY
136 auto __depend =
reinterpret_cast<void(*)()
>(&pthread_create);
138 auto __depend =
nullptr;
140 using _Wrapper = _Call_wrapper<_Callable, _Args...>;
143 _M_start_thread(
_State_ptr(
new _State_impl<_Wrapper>(
144 std::forward<_Callable>(__f), std::forward<_Args>(__args)...)),
147 #endif // _GLIBCXX_HAS_GTHREADS
155 thread(
const thread&) =
delete;
157 thread(thread&& __t) noexcept
160 thread&
operator=(
const thread&) =
delete;
171 swap(thread& __t) noexcept
172 { std::swap(_M_id, __t._M_id); }
175 joinable() const noexcept
176 {
return !(_M_id == id()); }
192 {
return _M_id._M_thread; }
196 hardware_concurrency() noexcept;
198 #ifdef _GLIBCXX_HAS_GTHREADS
200 template<
typename _Callable>
201 struct _State_impl :
public _State
205 template<
typename... _Args>
206 _State_impl(_Args&&... __args)
207 : _M_func{{std::forward<_Args>(__args)...}}
211 _M_run() { _M_func(); }
215 _M_start_thread(_State_ptr,
void (*)());
217 #if _GLIBCXX_THREAD_ABI_COMPAT
220 typedef shared_ptr<_Impl_base> __shared_base_type;
223 __shared_base_type _M_this_ptr;
224 virtual ~_Impl_base() =
default;
225 virtual void _M_run() = 0;
230 _M_start_thread(__shared_base_type,
void (*)());
233 _M_start_thread(__shared_base_type);
238 template<
typename _Tuple>
245 template<
typename _Fn,
typename... _Args>
246 struct __result<tuple<_Fn, _Args...>>
247 : __invoke_result<_Fn, _Args...>
250 template<
size_t... _Ind>
251 typename __result<_Tuple>::type
252 _M_invoke(_Index_tuple<_Ind...>)
253 {
return std::__invoke(std::get<_Ind>(
std::move(_M_t))...); }
255 typename __result<_Tuple>::type
259 =
typename _Build_index_tuple<tuple_size<_Tuple>::value>::__type;
260 return _M_invoke(_Indices());
265 template<
typename... _Tp>
266 using _Call_wrapper = _Invoker<tuple<typename decay<_Tp>::type...>>;
267 #endif // _GLIBCXX_HAS_GTHREADS
270 #ifndef _GLIBCXX_HAS_GTHREADS
271 inline void thread::join() { std::__throw_system_error(EINVAL); }
272 inline void thread::detach() { std::__throw_system_error(EINVAL); }
273 inline unsigned int thread::hardware_concurrency() noexcept {
return 0; }
277 swap(thread& __x, thread& __y) noexcept
281 operator==(thread::id __x, thread::id __y) noexcept
287 return __x._M_thread == __y._M_thread;
296 :
public __hash_base<size_t, thread::id>
299 operator()(
const thread::id& __id)
const noexcept
300 {
return std::_Hash_impl::hash(__id._M_thread); }
303 namespace this_thread
309 #ifndef _GLIBCXX_HAS_GTHREADS
311 #elif defined _GLIBCXX_NATIVE_THREAD_ID
322 #if defined _GLIBCXX_HAS_GTHREADS && defined _GLIBCXX_USE_SCHED_YIELD
331 _GLIBCXX_END_NAMESPACE_VERSION
335 #endif // _GLIBCXX_THREAD_H
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
Primary class template hash.
native_handle_type native_handle()
20.7.1.2 unique_ptr for single objects.
void yield() noexcept
this_thread::yield
thread::id get_id() noexcept
this_thread::get_id
Template class basic_ostream.
void terminate() noexcept
auto_ptr & operator=(auto_ptr &__a)
auto_ptr assignment operator.