开发者

how are pthreads on linux seen by scheduler

I've a question regarding pthread implementation on Linux.

Suppose a process has 5 threads. Now how does the scheduler sees these threads (or doesnt see at all). e.g. When scheduler is invoked, does it only schedule the main process, and then its the onus of the main process to schedule between ea开发者_运维问答ch of its thread.

Or is it the other way, that scheduler schedules each thread as if it is a separate process.


For modern Linux (NPTL pthread implementation), the scheduler schedules threads, a thread is considered a "Light-weight process". pthread_create is implemented in terms of the clone system call.


Linux schedules every thread as if it is a Process with scope as PTHREAD_SCOPE_SYSTEM. The nptl implementation can utilize multiple CPUs.


As Logan said, every thread is scheduled independently.

However, if you wish you may use Linux process control groups to schedule groups of threads instead.

Process control groups make the scheduling a little more inefficient, but it can be much more fair.

One use that has become very popular is to put all of the processes and threads created by each TTY into a control group per TTY. This results in all of a user's graphical applications being scheduled at the same level as his 24-thread kernel compile that he launched in a terminal window. The graphic applications get 50% and the compilation gets 50%. If he opens another terminal window and begins to compile glibc with another 24 threads, it shifts to 33% desktop applications, 33% kernel compile and 33% glibc compile.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜