如何为c中的线程分配优先级 [英] how to assign the priority to the threads in c

查看:104
本文介绍了如何为c中的线程分配优先级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个线程..

但我不知道如何为这些线程分配优先级..


你能帮我吗……

i create a thread..

but i don''t know how to assign the priority to those threads..


can you help me...............

推荐答案

Thread t = new Thread(() => { Console.WriteLine("Doing some work"); });
t.Priority = ThreadPriority.AboveNormal; //Assign priority here



请至少向Google提出这样的简单问题.



Please atleast google for such simple questions.


SetThreadPriority [^].
You''ll find sample there


我会警告您不要更改优先级.首先,它通常不会提高程序的吞吐量.想一想:您什么都不会加速,只是使用更多的CPU,而牺牲了其他线程.

更重要的是,通常尝试更改优先级是指示错误使用了线程以及对线程同步原语缺乏了解.规则是:如果线程工作不正常,则更改优先级将无法解决问题.

—SA
I would warn you against changing priorities. First, it does not usually improve the program throughput. Think about it: you don''t accelerate anything, you just use more of the CPU at the expense of other threads.

More importantly, usually an attempt to change priorities is the indication of incorrect use of threading and lack of knowledge of thread synchronization primitives. The rule is: if threading works incorrectly, changing of priorities cannot fix it.

—SA


这篇关于如何为c中的线程分配优先级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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