linux 线程切换效率与进程切换效率相差究竟有多大?

Posted brucemengbm

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了linux 线程切换效率与进程切换效率相差究竟有多大?相关的知识,希望对你有一定的参考价值。

Author:DriverMonkey

Mail:[email protected]

Phone:13410905075

QQ:196568501


Are Linux threads the same as other implementations?

    No. They are better -- while mostly keeping the same API. As stated above, most multithreaded OSs define a thread separately from processes. Linus Torvalds has defined that a thread is a "context of execution" (COE). This means that only one process/thread table and one scheduler is needed. Also the scheduler has been optomized so that the switching time for threads vs. tasks varies little--about 1.7us (threads) and 1.8us (fork) on a 75MHz Pentium.

    Traditionally, a thread was just a CPU (and some other minimal state) state with the process containing the remains (data, stack, I/O, signals). This would lend itself to very fast switching but would cause basic problems (e.g. what do "fork()" or "execve()" calls mean when executed by a thread?

    ).

    Consider Linux threads as a superset of this functionality: they still can switch fast and share process parts, but they can also identify what parts get shared and have no problems with execve() calls. There are four flags that determine the level of sharing:


以上是关于linux 线程切换效率与进程切换效率相差究竟有多大?的主要内容,如果未能解决你的问题,请参考以下文章

进程线程协程对比

进程与线程

进程调度

进程和线程的区别(简要总结)

多任务-python实现-进程,协程,线程总结(2.1.16)

单线程多线程和多进程的效率对比实验