国产精品天干天干,亚洲毛片在线,日韩gay小鲜肉啪啪18禁,女同Gay自慰喷水

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

分享到微博請遵守國家法律
林州市| 沾益县| 龙游县| 舟曲县| 班戈县| 平塘县| 资阳市| 金阳县| 永顺县| 安丘市| 福清市| 丰镇市| 门源| 射洪县| 丰都县| 隆安县| 安阳县| 武功县| 新田县| 徐州市| 广平县| 芒康县| 莫力| 龙口市| 安平县| 江达县| 三门县| 蒲城县| 临沂市| 杭锦旗| 宾川县| 溧阳市| 开江县| 卓资县| 灵丘县| 周口市| 太白县| 微博| 永嘉县| 陆河县| 武清区|