开发者

Threads Vs Processes Generally

开发者 https://www.devze.com 2023-03-05 17:59 出处:网络
1) Why is thread creation less expensive than process creation? 2) What is the difference between a thread and a subprocess? How would this relate to the above quest开发者_开发问答ion?When a process

1) Why is thread creation less expensive than process creation?

2) What is the difference between a thread and a subprocess? How would this relate to the above quest开发者_开发问答ion?


When a process is created it is allocated heap and stack memory. Threads on the other hand only get a stack and share the heap with the parent process. This means that even if you just consider memory allocation it is more "expensive" to create a process than a thread.

Subprocesses are simply processes that were created by another process. They are otherwise independent and get their own memory space. Here's an article that goes into some more detail.


The answer to this question is probably very OS dependent but a general rule :

  1. Threads of a process live in the same virtual memory space as their parent. So a thread creation is less expensive than a process creation because the underlying operating system doesn't need to create a full virtual memory space.

  2. A subprocess is just another process spawned by a parent.

0

精彩评论

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