30 #ifndef _GLIBCXX_THREAD_H
31 #define _GLIBCXX_THREAD_H 1
33 #ifdef _GLIBCXX_SYSHDR
34 #pragma GCC system_header
37 #if __cplusplus >= 201103L
47 #ifdef _GLIBCXX_HAS_GTHREADS
48 # include <bits/gthr.h>
54 namespace std _GLIBCXX_VISIBILITY(default)
56 _GLIBCXX_BEGIN_NAMESPACE_VERSION
58 #if __glibcxx_formatters
59 template<
typename,
typename>
class formatter;
87 #ifdef _GLIBCXX_HAS_GTHREADS
88 using native_handle_type = __gthread_t;
90 using native_handle_type = int;
100 native_handle_type _M_thread;
103 id() noexcept : _M_thread() { }
106 id(native_handle_type __id) : _M_thread(__id) { }
113 operator==(
id __x,
id __y) noexcept;
115 #if __cpp_lib_three_way_comparison
116 friend strong_ordering
117 operator<=>(
id __x,
id __y) noexcept;
123 template<
class _CharT,
class _Traits>
127 #if __glibcxx_formatters
128 friend formatter<id, char>;
129 friend formatter<id, wchar_t>;
139 template<
typename _Tp>
140 using __not_same = __not_<is_same<__remove_cvref_t<_Tp>,
thread>>;
143 thread() noexcept = default;
145 #ifdef _GLIBCXX_HAS_GTHREADS
154 _M_thread_deps_never_run() {
155 #ifdef GTHR_ACTIVE_PROXY
156 reinterpret_cast<void (*)(
void)
>(&pthread_create)();
157 reinterpret_cast<void (*)(
void)
>(&pthread_join)();
162 template<
typename _Callable,
typename... _Args,
163 typename = _Require<__not_same<_Callable>>>
165 thread(_Callable&& __f, _Args&&... __args)
167 static_assert( __is_invocable<
typename decay<_Callable>::type,
168 typename decay<_Args>::type...>::value,
169 "std::thread arguments must be invocable after conversion to rvalues"
172 using _Wrapper = _Call_wrapper<_Callable, _Args...>;
175 _M_start_thread(_State_ptr(
new _State_impl<_Wrapper>(
176 std::forward<_Callable>(__f), std::forward<_Args>(__args)...)),
177 _M_thread_deps_never_run);
187 thread(
const thread&) =
delete;
189 thread(thread&& __t) noexcept
192 thread& operator=(
const thread&) =
delete;
194 thread& operator=(thread&& __t) noexcept
203 swap(thread& __t) noexcept
204 { std::swap(_M_id, __t._M_id); }
207 joinable() const noexcept
208 {
return !(_M_id == id()); }
224 {
return _M_id._M_thread; }
228 hardware_concurrency() noexcept;
230 #ifdef _GLIBCXX_HAS_GTHREADS
231 #ifndef _GLIBCXX_THREAD_IMPL
239 virtual void _M_run() = 0;
241 using _State_ptr = unique_ptr<_State>;
244 template<
typename _Callable>
245 struct _State_impl :
public _State
249 template<
typename... _Args>
250 _State_impl(_Args&&... __args)
255 _M_run() { _M_func(); }
259 _M_start_thread(_State_ptr,
void (*)());
261 #if _GLIBCXX_THREAD_ABI_COMPAT
264 typedef shared_ptr<_Impl_base> __shared_base_type;
267 __shared_base_type _M_this_ptr;
268 virtual ~_Impl_base() =
default;
269 virtual void _M_run() = 0;
274 _M_start_thread(__shared_base_type,
void (*)());
277 _M_start_thread(__shared_base_type);
282 template<
typename _Tuple>
285 template<
typename... _Args>
287 _Invoker(_Args&&... __args)
295 template<
typename _Fn,
typename... _Args>
296 struct __result<tuple<_Fn, _Args...>>
297 : __invoke_result<_Fn, _Args...>
300 template<
size_t... _Ind>
301 typename __result<_Tuple>::type
302 _M_invoke(_Index_tuple<_Ind...>)
305 typename __result<_Tuple>::type
309 =
typename _Build_index_tuple<tuple_size<_Tuple>::value>::__type;
310 return _M_invoke(_Indices());
316 template<
typename... _Tp>
317 using _Call_wrapper = _Invoker<tuple<typename decay<_Tp>::type...>>;
322 #ifndef _GLIBCXX_HAS_GTHREADS
323 inline void thread::join() { std::__throw_system_error(EINVAL); }
324 inline void thread::detach() { std::__throw_system_error(EINVAL); }
325 inline unsigned int thread::hardware_concurrency() noexcept {
return 0; }
330 swap(thread& __x, thread& __y) noexcept
335 operator==(thread::id __x, thread::id __y) noexcept
341 return __x._M_thread == __y._M_thread;
350 :
public __hash_base<size_t, thread::id>
353 operator()(
const thread::id& __id)
const noexcept
354 {
return std::_Hash_impl::hash(__id._M_thread); }
357 namespace this_thread
363 #ifndef _GLIBCXX_HAS_GTHREADS
365 #elif defined _GLIBCXX_NATIVE_THREAD_ID
376 #if defined _GLIBCXX_HAS_GTHREADS && defined _GLIBCXX_USE_SCHED_YIELD
385 _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.
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()