Windows Phone 8.1上的std :: this_thread :: sleep_for坏了吗? [英] std::this_thread::sleep_for broken on windows phone 8.1 ?

查看:70
本文介绍了Windows Phone 8.1上的std :: this_thread :: sleep_for坏了吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


您好


我正在将我的游戏引擎移植到Windows Phone 8.1(主要是C ++)在五天之后它终于编译和链接... 
$


现在我正在尝试运行它...引擎本身使用std :: thread来做一些后台操作(它是CROSS PLATFORM - 所以我不能轻易取代那些使用WinRT 基于
任务的pararelism,因为它会破坏其他(Android / iOS)平台 - 而且我的魔杖尽可能少地依赖于平台 - OpenGLES与DX11就够了。)


代码中的某处有一个用于检查特定变量(Atomic)的构造并停止MAIN线程,直到varialble获得特定值

(在完成此检查的90%情况下,变量实际上已设置且无需等待,但有时(主要在调试版本中)工作线程需要更多时间并且
停止主线程调用:



std :: chrono ::毫秒持续时间(10) ; // 10毫秒

std :: this_thread :: sleep_for(持续时间);
$


这很好,好像没有设置变量一样在失速时间内,主线程应该继续执行

但是在Windows Phone MAIN线程从未从'std :: this_thread :: sleep_for'返回:/



为了实验我将上面的代码放在旋转的立方体样本中(来自VS 2013项目模板),效果是一样的...... std :: this_thread :: sleep_for永远不会返回

任何想法为什么,如何解决这个问题,如何在Windows 8.1上模拟Sleep / SleepEx?
$

解决方案

请参阅
http://blogs.msdn.com/b/win8devsupport/archive/2012/11/28/introduce-multi-thread-programming-in-windows-store-apps -part-ii.aspx

Hi

I'm in the process of porting my game engine to windows phone 8.1 (C++ mainly) after may days it's finally compile and link ... 

Now I'm trying to run it ... engine itself uses std::thread to do some background operations (it's CROSS PLATFORM - so I cant easily replace those with WinRT 
task based pararelism as it will break other (Android/iOS) platforms - and I wand as little as possible platform dependent code - OpenGLES vs. DX11 is enough).

somewhere in code there is construct used that checks the particular variable (Atomic) and stalls the MAIN thread until the varialble gets particular value
(in 90% of cases when this check is done the variable is actually set and no wait is need, but sometimes (mainly in debug builds) the worker thread needs some more time and
stalls the main thread calling:

std::chrono::milliseconds duration( 10 ); // 10 miliseconds
std::this_thread::sleep_for( duration );

this is fine as if the variable is not set within the stall time, main thread should continue it's execution
but on windows phone MAIN thread NEVER returns from 'std::this_thread::sleep_for' :/

for sake of experiment i'v put the code from above in the rotating cube sample (from VS 2013 project templates) and the effect is that same ... std::this_thread::sleep_for never returns
any ideas why, how to fix this, how to emulate Sleep/SleepEx on windows phine 8.1 ?

解决方案

Please see http://blogs.msdn.com/b/win8devsupport/archive/2012/11/28/introduce-multi-thread-programming-in-windows-store-apps-part-ii.aspx


这篇关于Windows Phone 8.1上的std :: this_thread :: sleep_for坏了吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆