C++ 11的 std::this_thread名字实现了很多线程辅助函数,例如get_id(), yeild()等,this_thread代码如下:
namespace this_thread {
thread::id get_id() _NOEXCEPT;
inline void yield() _NOEXCEPT
{ // give up balance of time slice
_Thrd_yield();
}
inline void sleep_until(const stdext::threads::xtime *_Abs_time)
{ // sleep until _Abs_time
_Thrd_sleep(_Abs_time);
}
template inline
void sleep_until(
const chrono::time_point& _Abs_time)
{ // sleep until time point
stdext::threads::xtime _Tgt;
_Tgt.sec = chrono::duration_cast(
_Abs_time.time_since_epoch()).count();
_Tgt.nsec = (long)chrono::duration_cast(
_Abs_time.time_since_epoch() - chrono::seconds(_Tgt.sec)).count();
sleep_until(&_Tgt);
}
template inline
void sleep_for(const chrono::duration&a