最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(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的評論 (共 條)

分享到微博請遵守國家法律
保定市| 旬邑县| 温州市| 青田县| 绥阳县| 来宾市| 长葛市| 枣阳市| 嘉荫县| 亚东县| 文登市| 连平县| 呼伦贝尔市| 中卫市| 老河口市| 九江县| 罗城| 恩平市| 闻喜县| 府谷县| 屯门区| 琼海市| 无极县| 会东县| 顺义区| 蓝田县| 开鲁县| 崇信县| 海城市| 房山区| 台湾省| 大余县| 江门市| 高雄县| 和龙市| 石首市| 临高县| 黄龙县| 清徐县| 织金县| 巴塘县|