首页
社区
课程
招聘
[旧帖] windows核心编程上的一个败笔,bug 0.00雪花
发表于: 2014-8-23 17:49 1456

[旧帖] windows核心编程上的一个败笔,bug 0.00雪花

2014-8-23 17:49
1456
核心编程第5版本  8.3节

代码:

volatile BOOL g_fFinishedCalculation = FALSE
主线程
{
创建子线程
while(!g_fFinishedCalculation);

}

子线程代码:
{
g_fFinishedCalculation = TRUE;
}

作者在 代码这里有一段文字:

Another problem with the polling method used in the previous code fragment is that the BOOL variable g_fFinishedCalculation might never be set to TRUE. This can happen if the primary thread has a higher priority than the thread executing the RecalcFunc function. In this case, the system never assigns any time slices to the RecalcFunc thread, which never executes the statement that sets g_fFinishedCalculation to TRUE. If the thread executing the _tWinMain function is put to sleep instead of polling, it is not scheduled time and the system can schedule time to lower-priority threads, such as the RecalcFunc thread, allowing them to execute.

问题: 为什么优先级会导致 子线程 没有执行机会 ?

xp单核 系统上 做个实验, 发现 子线程是有机会执行的。

难道作者错了不成?

还有windows核心编程 上,提到过 动态提升线程优先级。

很明显,子线程会被动态提升到15.  自然会打破优先级逆转的问题。
所以子线程是有机会执行。

[课程]FART 脱壳王!加量不加价!FART作者讲授!

收藏
免费 0
支持
分享
最新回复 (1)
雪    币: 0
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
2
Windows 核心编程5 基于Windows NT 6也就是Vista系统,你可以在Windows 7上测试一下。Windows XP的权限没那么完备。
2014-8-27 15:43
0
游客
登录 | 注册 方可回帖
返回
//