您当前的位置: 首页 >  c++

令狐掌门

暂无认证

  • 0浏览

    0关注

    513博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

C++11多线程(二):this_thread 名字空间

令狐掌门 发布时间:2020-02-21 21:36:39 ,浏览量:0

     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
关注
打赏
1652240117
查看更多评论
立即登录/注册

微信扫码登录

0.0591s