29 #ifndef _GLIBCXX_THREAD
30 #define _GLIBCXX_THREAD 1
32 #pragma GCC system_header
34 #ifndef __GXX_EXPERIMENTAL_CXX0X__
45 #include <bits/gthr.h>
47 #if defined(_GLIBCXX_HAS_GTHREADS) && defined(_GLIBCXX_USE_C99_STDINT_TR1)
63 typedef __gthread_t native_handle_type;
65 typedef shared_ptr<_Impl_base> __shared_base_type;
70 native_handle_type _M_thread;
73 id() : _M_thread() { }
76 id(native_handle_type __id) : _M_thread(__id) { }
83 {
return __gthread_equal(__x._M_thread, __y._M_thread); }
87 {
return __x._M_thread < __y._M_thread; }
89 template<
class _CharT,
class _Traits>
91 operator<<(basic_ostream<_CharT, _Traits>&& __out,
thread::id __id);
98 __shared_base_type _M_this_ptr;
100 virtual ~_Impl_base() =
default;
102 virtual void _M_run() = 0;
105 template<
typename _Callable>
106 struct _Impl :
public _Impl_base
110 _Impl(_Callable&& __f) : _M_func(std::forward<_Callable>(__f))
114 _M_run() { _M_func(); }
122 thread(
const thread&) =
delete;
127 template<
typename _Callable>
128 explicit thread(_Callable __f)
129 { _M_start_thread(_M_make_routine<_Callable>(__f)); }
131 template<
typename _Callable,
typename... _Args>
132 thread(_Callable&& __f, _Args&&... __args)
133 { _M_start_thread(_M_make_routine(
std::bind(__f, __args...))); }
141 thread& operator=(
const thread&) =
delete;
143 thread& operator=(thread&& __t)
153 { std::swap(_M_id, __t._M_id); }
157 {
return !(_M_id == id()); }
173 {
return _M_id._M_thread; }
177 hardware_concurrency()
182 _M_start_thread(__shared_base_type);
184 template<
typename _Callable>
185 shared_ptr<_Impl<_Callable>>
186 _M_make_routine(_Callable&& __f)
189 return make_shared<_Impl<_Callable>>(std::forward<_Callable>(__f));
194 swap(thread& __x, thread& __y)
198 swap(thread&& __x, thread& __y)
202 swap(thread& __x, thread&& __y)
207 {
return !(__x == __y); }
210 operator<=(thread::id __x, thread::id __y)
211 {
return !(__y < __x); }
214 operator>(thread::id __x, thread::id __y)
215 {
return __y < __x; }
218 operator>=(thread::id __x, thread::id __y)
219 {
return !(__x < __y); }
221 template<
class _CharT,
class _Traits>
222 inline basic_ostream<_CharT, _Traits>&
223 operator<<(basic_ostream<_CharT, _Traits>&& __out, thread::id __id)
225 if (__id == thread::id())
226 return __out <<
"thread::id of a non-executing thread";
228 return __out << __id._M_thread;
235 namespace this_thread
241 #ifdef _GLIBCXX_USE_SCHED_YIELD
245 { __gthread_yield(); }
248 #ifdef _GLIBCXX_USE_NANOSLEEP
250 template<
typename _Clock,
typename _Duration>
256 template<
typename _Rep,
typename _Period>
266 __gthread_time_t __ts =
268 static_cast<std::time_t
>(__s.count()),
269 static_cast<long>(__ns.count())
272 ::nanosleep(&__ts, 0);
280 #endif // _GLIBCXX_HAS_GTHREADS && _GLIBCXX_USE_C99_STDINT_TR1
282 #endif // __GXX_EXPERIMENTAL_CXX0X__
284 #endif // _GLIBCXX_THREAD
bool operator!=(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return false if x is equal to y.
thread::id get_id()
get_id
_ToDuration duration_cast(const duration< _Rep, _Period > &__d)
duration_cast
void terminate() __attribute__((__noreturn__))
void sleep_for(const chrono::duration< _Rep, _Period > &__rtime)
sleep_for
_Bind< typename _Maybe_wrap_member_pointer< _Functor >::type(_ArgTypes...)> bind(_Functor __f, _ArgTypes...__args)
bind
native_handle_type native_handle()
Controlling output.This is the base class for all output streams. It provides text formatting of all ...
void sleep_until(const chrono::time_point< _Clock, _Duration > &__atime)
sleep_until