五月天青色头像情侣网名,国产亚洲av片在线观看18女人,黑人巨茎大战俄罗斯美女,扒下她的小内裤打屁股

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

Process vs Thread

2023-03-20 23:01 作者:C20先生  | 我要投稿

Process vs Thread

what's the difference between process and thread?

This is a common interview question.

That's take a look.

To better answer this question.

Let's first understand what a program is?

A program is an executable file.

It contains the code or a set of processing instructions that is stored as a file on disk.

When the code in the program is loaded into memory and executed by processor, it becomes a process. An active process also includes the resources the program needs to run. These resources are managed by the operating system.

Some examples of processor registers ,program counters, stack pointers, memory pages assigned to the process for his heap and stack etc.

there is an important property of a process that is worth mentioning, each process is his own memory address space.

One process cannot corrupt the memory space of another process. This means that when one process malfunctions ,other processes keep running.



Chrom is famous for taking advantage of this

process isolation by running each Tab in its own process when one Tab misbehaves due to a bug or a malicious attack other tabs are unaffected.

Now, what is a threat?

A threat is a unit of execution within a process. A process has a at least one threat, it is called a Main Thread. It is not uncommon for a process to have many threats, each threat has his own stack, earlier we mention registers , program counters, stack pointers

as being part of a process.

It is more accurate to say that those things belong to a threat.

Threads within a process share a memory address space , it is possible to communicate

between threats using that share memory space . However one misbehave thread could bring down the entire process.

How does the operating system run the thread or process?

On the CPU, this is handle by context switching , during a context switch, one process is switch out of the CPU , so another process can run .

The operating system,stores the states of the current running process , so the process can be restore and resume execution at a later point, it then restores the previously safe states of a different process and resumes execution for that process.

contact switching is expensive, it involves saving and loading of registers ,switching our memory pages and updating various kernel data structures


Switching execution between threads also requires context switching

it is generally faster to switch context between threads than between processes .

There are fewer stage to track and more importantly

since threads share the same memory address space, there is no need to switch our virtual memory pages which is one of the more expensive operation during a context switch.

Context switching is so costly, there are other mechanisms to try to minimize it.

Some examples of fibers and coroutines

For even lower context switching cost , in general , they are cooperatively scheduled that is they must you control for other to run .

In other words, the application is self handles task scheduling. It is a responsibility of the application to make sure a long running task is broken up by uting perviodiclally .













Process vs Thread的評論 (共 條)

分享到微博請遵守國家法律
梅河口市| 阿坝| 大荔县| 准格尔旗| 象州县| 玛多县| 绥德县| 咸阳市| 蕲春县| 延寿县| 云霄县| 平顶山市| 乌兰浩特市| 高碑店市| 凉山| 五大连池市| 定陶县| 锦州市| 玛多县| 张家口市| 德惠市| 洱源县| 金门县| 扬州市| 温州市| 白城市| 比如县| 镇赉县| 德化县| 鄱阳县| 蛟河市| 贺州市| 图片| 新化县| 酒泉市| 濮阳县| 志丹县| 克山县| 昂仁县| 长治县| 乐安县|