多线程的优先级

jin_ok 2010-07-01 10:30:59
如果有10个线程,默认情况下系统是不是给这10个线程指定一个优先级?谁分配了这10个线程的执行顺序?,怎样分配?
...全文
136 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
宇峰科技 2010-07-02
  • 打赏
  • 举报
回复
如果不指定,就由系统自由分配,当然也可以指定优先级
beijingbeerman 2010-07-02
  • 打赏
  • 举报
回复
如果不指定,使用的是默认优先级。不过在c#中线程的优先级没什么用。我试验过。
jianuMan 2010-07-02
  • 打赏
  • 举报
回复
有个默认的优先级
  • 打赏
  • 举报
回复
好像这个和操作系统有关系...
whb147 2010-07-01
  • 打赏
  • 举报
回复
一般情况下,谁有空就谁去干活
yangjinCK 2010-07-01
  • 打赏
  • 举报
回复
线程会自动分配
queen25 2010-07-01
  • 打赏
  • 举报
回复
http://cache.baidu.com/c?m=9f65cb4a8c8507ed4fece763104681254743801464849446289fc45f93130a1c187bf4ba53634a5996d27b1355e81702fdf14034774477a3de95c81cd2ace32238ff22230017913562c418dfdc3024d656924de8df1ae5adf14284ded8c4ab5044cb23120bf4e7fd2e1764cb78816526e3d78e39134863cbfa416fe828033e9e5357c742ee97397977f5e1a9585bc25ac7106580de35a73f62a262d0086b2353d13aa6785031319058568c534c0185ea2df05a795753c65fb2c9d6c7985ffdd9fd30e8edbba538e16af1c49aee07456725fa32bfdbbeb02a653515a9c0c962c025bd8afbcb38fe62a3072cbb4a075e7ccf1b83f48b4082684d84e37f8d233527581da9b3638f05676e41bf4e12a66bc462b0fe613dddfdec8f886431b8e8cf64768ebacf33a01d0a34ec565567bce02501&p=893bdd16d9c25fe609bd9b7847&user=baidu
okidasougo 2010-07-01
  • 打赏
  • 举报
回复
学习学习~~好东西
dazhabai 2010-07-01
  • 打赏
  • 举报
回复

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace Ex_20_4
{
class Program
{
static void Main(string[] args)
{
MyThreadClass o1 = new MyThreadClass("hackcat1,我的优先级是:Normal!");
Thread t1 = new Thread(o1.ThreadMain);
t1.Priority = ThreadPriority.Normal;
t1.Start();
MyThreadClass o2 = new MyThreadClass("hackcat2,我的优先级是:Normal!");
Thread t2 = new Thread(o2.ThreadMain);
t2.Priority = ThreadPriority.Normal;
t2.Start();
MyThreadClass o3 = new MyThreadClass("hackcat3,我的优先级是:Normal!");
Thread t3 = new Thread(o3.ThreadMain);
t3.Priority = ThreadPriority.Normal;
t3.Start();
MyThreadClass o4 = new MyThreadClass("hackcat4,我的优先级是:Normal!");
Thread t4 = new Thread(o4.ThreadMain);
t4.Priority = ThreadPriority.Normal;
t4.Start();
Console.Read();
}
}
public class MyThreadClass
{
private String Msg;
public MyThreadClass(String Msg)
{
this.Msg = Msg;
}
public void ThreadMain()
{
Console.WriteLine("字段Msg的值是{0}", Msg);
}
}
}


跑了10来次,发现每次结果都不一样,这个是不是随机的?
dazhabai 2010-07-01
  • 打赏
  • 举报
回复
//
// Summary:
// The System.Threading.Thread can be scheduled after threads with AboveNormal
// priority and before those with BelowNormal priority. Threads have Normal
// priority by default.
Normal = 2,
dazhabai 2010-07-01
  • 打赏
  • 举报
回复
高优先级的线程可以完全阻止低优先级的线程执行,因此在改变线程的优先级时要特别小心。线程的优先级可以定义为ThreadPriority枚举的值,即Highest、AboveNormal、Normal、BelowNormal和 Lowest。
daihua_1113 2010-07-01
  • 打赏
  • 举报
回复
配个好电脑 省担心这个问题 cpu自己解决

110,566

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧