-
-
[旧帖]
windows核心编程上的一个败笔,bug
0.00雪花
-
发表于:
2014-8-23 17:49
1456
-
[旧帖] windows核心编程上的一个败笔,bug
0.00雪花
核心编程第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作者讲授!