29 #ifndef _GLIBCXX_THREAD
30 #define _GLIBCXX_THREAD 1
32 #pragma GCC system_header
34 #ifndef __GXX_EXPERIMENTAL_CXX0X__
43 #include <bits/gthr.h>
45 #if defined(_GLIBCXX_HAS_GTHREADS) && defined(_GLIBCXX_USE_C99_STDINT_TR1)
47 namespace std _GLIBCXX_VISIBILITY(default)
49 _GLIBCXX_BEGIN_NAMESPACE_VERSION
63 typedef __gthread_t native_handle_type;
70 native_handle_type _M_thread;
73 id() noexcept : _M_thread() { }
76 id(native_handle_type __id) : _M_thread(__id) { }
80 friend class hash<thread::
id>;
83 operator==(thread::id __x, thread::id __y) noexcept
84 {
return __gthread_equal(__x._M_thread, __y._M_thread); }
88 {
return __x._M_thread < __y._M_thread; }
90 template<
class _CharT,
class _Traits>
92 operator<<(basic_ostream<_CharT, _Traits>& __out,
thread::id __id);
101 inline virtual ~_Impl_base();
103 virtual void _M_run() = 0;
106 template<
typename _Callable>
107 struct _Impl :
public _Impl_base
111 _Impl(_Callable&& __f) : _M_func(std::
forward<_Callable>(__f))
115 _M_run() { _M_func(); }
122 thread() noexcept = default;
123 thread(thread&) = delete;
124 thread(const thread&) = delete;
126 thread(thread&& __t) noexcept
129 template<
typename _Callable,
typename... _Args>
131 thread(_Callable&& __f, _Args&&... __args)
133 _M_start_thread(_M_make_routine(std::__bind_simple(
134 std::forward<_Callable>(__f),
135 std::forward<_Args>(__args)...)));
144 thread& operator=(
const thread&) =
delete;
146 thread& operator=(thread&& __t) noexcept
155 swap(thread& __t) noexcept
156 { std::swap(_M_id, __t._M_id); }
159 joinable() const noexcept
160 {
return !(_M_id == id()); }
169 get_id() const noexcept
176 {
return _M_id._M_thread; }
180 hardware_concurrency() noexcept;
184 _M_start_thread(__shared_base_type);
186 template<typename _Callable>
188 _M_make_routine(_Callable&& __f)
191 return std::make_shared<_Impl<_Callable>>(std::forward<_Callable>(__f));
195 inline thread::_Impl_base::~_Impl_base() =
default;
198 swap(thread& __x, thread& __y) noexcept
202 operator!=(thread::id __x, thread::id __y) noexcept
203 {
return !(__x == __y); }
206 operator<=(thread::id __x, thread::id __y) noexcept
207 {
return !(__y < __x); }
210 operator>(thread::id __x, thread::id __y) noexcept
211 {
return __y < __x; }
214 operator>=(thread::id __x, thread::id __y) noexcept
215 {
return !(__x < __y); }
221 :
public __hash_base<size_t, thread::id>
224 operator()(
const thread::id& __id)
const noexcept
225 {
return std::_Hash_impl::hash(__id._M_thread); }
228 template<
class _CharT,
class _Traits>
230 operator<<(basic_ostream<_CharT, _Traits>& __out,
thread::id __id)
233 return __out <<
"thread::id of a non-executing thread";
235 return __out << __id._M_thread;
238 _GLIBCXX_END_NAMESPACE_VERSION
244 namespace this_thread
246 _GLIBCXX_BEGIN_NAMESPACE_VERSION
252 #ifdef _GLIBCXX_USE_SCHED_YIELD
256 { __gthread_yield(); }
259 #ifdef _GLIBCXX_USE_NANOSLEEP
261 template<
typename _Rep,
typename _Period>
271 __gthread_time_t __ts =
273 static_cast<std::time_t
>(__s.count()),
274 static_cast<long>(__ns.count())
277 ::nanosleep(&__ts, 0);
281 template<
typename _Clock,
typename _Duration>
287 _GLIBCXX_END_NAMESPACE_VERSION
294 #endif // _GLIBCXX_HAS_GTHREADS && _GLIBCXX_USE_C99_STDINT_TR1
296 #endif // __GXX_EXPERIMENTAL_CXX0X__
298 #endif // _GLIBCXX_THREAD
void sleep_for(const chrono::duration< _Rep, _Period > &__rtime)
sleep_for
constexpr _Tp && forward(typename std::remove_reference< _Tp >::type &__t) noexcept
Forward an lvalue.
Template class basic_ostream.This is the base class for all output streams. It provides text formatti...
void terminate() _GLIBCXX_USE_NOEXCEPT __attribute__((__noreturn__))
void sleep_until(const chrono::time_point< _Clock, _Duration > &__atime)
sleep_until
constexpr enable_if< __is_duration< _ToDur >::value, _ToDur >::type duration_cast(const duration< _Rep, _Period > &__d)
duration_cast
native_handle_type native_handle()
void yield() noexcept
yield
Primary class template hash.
thread::id get_id() noexcept
get_id