namespace HelloWorld
{
class Program
{
static void Main(string[] args)
{
Thread t = new Thread(() => WriteY("11"));
t.Start();
t.IsBackground = true;
Thread.CurrentThread.Priority = ThreadPriority.Highest;
for (int i = 0; i < 1000; i++) Console.Write("x");
System.Console.ReadLine();
}
static void WriteY(string ss)
{
for (int i = 0; i < 1000; i++)
Console.Write(ss);
System.Console.ReadLine();
}
}
}
您好,我认为“x”线程应该首先完成,因为它的优先级最高。但结果是他们仍然在切换。
首先,无论优先顺序如何,您不能对哪个并行作业首先完成做出任何假设.
另外,请阅读 Jeff Atwood 撰写的这篇文章,了解为什么使用线程优先级是一个坏主意。
http://www.codinghorror.com/blog/2006/08/thread-priorities-are-evil.html
如果是 tl;dr,只需引用一句:无论您是多么出色的程序员,我几乎可以保证您无法比在您的操作系统中编写调度程序的程序员聪明.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)