Thread in Linux
来源:互联网 发布:淘宝禁售商品的是 编辑:程序博客网 时间:2024/05/16 14:44
- If I create a highest priority thread, is that thread will run immediately ?
I think so.. The next thread should be you……
OK, first , let's understand that if you want tospecify a priority to a thread ,it means that it is a real time thread. And ofcourse , the real time thread has higher priority than any non-real-timethread.
If the system has no real time thread , and youcreate a real time thread , it will be scheduled immediately AND it will notstop until he is blocked.
If the system already has real time thread , butnew thread priority is higher, and also the new thread will be scheduledimmediately.
- An interesting example :
Int main()
{
- Create normal thread 1
- Create normal thread 2
- Create a real time thread 1 with priority 10
- Create a real time thread 2 with priority 20 // 20 is high than 10
}
Which thread will run first? Will the real timethread 2 has a chance to run??
Answer: real time thread 1 will run first
real timethread 2 has no chance to run , because real time thread 1 will preemptive allthe normal thread and that includes the main() thread!! It means real-timethread2 even has not a chance to be created!!!!!!
Real-time threadwill preemptive all the non real-time thread. Be careful!! Make sure yournormal thread has the chance to run!!
- A SCHED_FIFO process runs until either it is blocked by an I/O request, it is preemptivedby a higher priority process, or it callssched_yield.
- If have 3 thread with priority of 3, 4 ,5, what is the run sequence?
Thread 5 will always run only if he was blocked ;then thread 4 will get the cpu , only when both 5 and 4 are block then thread 3will get the cpu.
- Does preemptive means the highest priority thread will get the CPU whenever it is ready?
Yes. And in Linux ,all scheduling is preemptive no matter it is real time thread or non real-timethread. The only difference is that real-time thread has higher priority. (from1 to 99 for realtime thread, 0 is for non-real-time thread)
- Real thread in Linux? Means this thread is special than others?
Yes. That is the thread you created with FIFOROUND_RB.
pthread_attr_t thread_attr;
struct sched_param sch_param;
pthread_attr_init(&thread_attr);
pthread_attr_setschedpolicy(&thread_attr, SCHED_FIFO);
sch_param.sched_priority = 50;
pthread_attr_setschedparam(&thread_attr, &sch_param);
if(pthread_create(&g_display_int_thread_id,&thread_attr, display_init_thread, NULL))
{
assert(!"Error in create InitSvpClient thread");
}
- SCHED_RR & SCHED_FIFO mode , are they just the setting for thread with equal priority?
NO. If you create a thread with the schedulerattribute set to SCHED_RR or SCHED_FIFO mode, they are real-time thread.SCHED_RR is a variation of the SCHED_FIFO . The only difference is that forthread with equal priority , in _RR policy will share the CPU between them ,but for _FIFO mode, it is run as FIFO…. That mean only when one give up the cputhe other will get it.
- What is the default thread priority in Linux?
Nopriority. Default thread is non real time thread and the thread priority isdefault to 0. As all the normal thread has the same priority , so thescheduling police is the standard time sharing policy.
man sched_setscheduler , you will understand what is the scheduler policy for non realtime thread.
- What is the difference in thread scheduler between kernel 2.4 - 2.6?
- Pre-emptive point in the kernel http://www.rtcmagazine.com/articles/print_article/100132
- Before, when it is in the kernel mode (through a system call), it is not preemptive. Preemptive happens only when return back to user mode. It hurts the responsiveness sometimes.
- O(1) time for determine next process to run. http://www.ibm.com/developerworks/linux/library/l-scheduler/
- First , basically it is priority-base preemptive scheduler algorithm.
- We have total 140 priorities , 0-99 is for real time thread which is created through SCHED_FIFO or SCHED_RR. 100-139 is for normal thread.
- Scheduler always pick the head task in the highest priority task queue.
- Pre-emptive point in the kernel http://www.rtcmagazine.com/articles/print_article/100132
To make this process more efficient, a bitmap is used todefine when tasks are on a given priority list. Therefore, on mostarchitectures, a find-first-bit-setinstruction is used to find the highest priority bit set in one of five 32-bitwords
- Dynamic task prioritization
- This is not something new and this only apply for the normal thread (not use thread).
- The theory:
To prevent tasks from hogging the CPU and thus starving othertasks that need CPU access, the Linux 2.6 scheduler can dynamically alter atask's priority. It does so by penalizing tasks that are bound to a CPU andrewarding tasks that are I/O bound. I/O-bound tasks commonly use the CPU to setup an I/O and then sleep awaiting the completion of the I/O. This type ofbehavior gives other tasks access to the CPU.
- In which case high priority thread starvation other one? How to prevent it?
- A
- Preemptive
- You are highest priority thread and you never has a break
- How to prevent it ?
- A
- Thread in Linux
- Thread in linux
- Thread in WIN32 & Linux
- Linux process/thread in practice
- Getting thread count for proc in linux
- c multiple thread programming in linux
- linux里输入dbca时,出现exception in thread main
- Linux(centOS):Exception in thread "main" java.lang.UnsupportedClassVersionError***
- Linux rpm 报错Thread died in Berkeley DB library
- linux Thread
- Linux thread
- linux thread
- linux thread
- linux thread
- Java Thread in JVM
- Java Thread in JVM
- Thread In Java Technology
- Java Thread in JVM
- c++静态成员小结
- 车牌识别源码
- sp_addlinkedserver和sp_addlinkedsrvlogin
- 电销性能测试--20090801
- Wince6 Eboot中加入开机画面
- Thread in Linux
- 自己动手来auto guide
- 电脑操作,熟悉?(2)
- windows 7 RTM build 7600.16385安装step by step(虚拟光驱双系统方式)
- X-Ways.WinHex.v15.4.Incl.Keymaker-ZWT
- FOJ1011 Power String
- windows下IIS+Xcache配置-配置代码测试通过
- Hello
- 一个女孩写的经典代码~~~