- Thread is for execution
- Kernel level thread, physical parallelism
- Cores Divide work amount of physical cores / CPU
- Load balancing
- Data Splitting
- Which will lead to data dependency coodination and message passing
- Bad thing for multiple cores is this is hard for Testing and debugging
- User level thread only have logical parallelism
- Example, Read from user input is blocking; we have to work on it to make it logical parallelism
- Process is for resource
What is Program
Program是一個存在disk中且斷電或重啓不會消失可執行文件,存儲在存儲媒介中,以實體文件的形態存在面試
A program is an executable file residing on the disk (secondary storage) in a directory. It is also termed as a set of instructions stored in the secondary storage device that are intended to carry out a specific job. It is read into the primary memory and executed by the kernel.多線程
本文來自 Abbymz 的CSDN 博客 ,全文地址請點擊:https://blog.csdn.net/Abby210/article/details/51225034?utm_source=copyapp
或者能夠稱之爲persistently 的文件,斷電也不會消失。ide
What is Process ?
當program被執行以後,就變成了進程。執行者的權限和程序所需的資料都會載入到內存中,OS會給予這些內存單元一個pid。學習
Unit of resource ownership (allocation) and unit of protectionthis
text, Code of Programmer |
Data |
Heap |
Stack |
一個program能夠建立出不少個進程,關機或停電會死掉spa
Process的組成
- Permission user or kernel
- Priority
- Files
- ID
- Protected access to
- Processors
- other process
- Files
- I/O
- A virtual space that holds the process image
What is Thread ?
線程稱之爲Lightweight Process,一個進程能夠有多個線程,他們共享一片內存.net
- has access to the same data
- When one thread alters a data, other threads see the results
- When one thread open a file, other threads can also access that file.
Unit of dispatch or unit of execution線程
多線程的好處
- 開啓線程要快於開啓進程
- 關閉線程要快於關閉進程
- 切換線程要快於切換進程
- 線程能夠相互通信
什麼叫Multithreading
The ability of an OS to support multiple, concurrent paths of execution within a single process.debug
Process and thread states
- Ready
- new process usually set as read state
- At this time scheduler is not pick it up yet.
- If it get picked by scheduler and running in CPU, then goes to Running State
- If it get external event, something like lock, then goes to block
- Running,
- Scheduler picked it up, and CPU is run this instruction
- If it get finished, goes to Exit states
- If it get IO interrupts, goes to ready, blocked status
- If it can not get the resource which is conflict with other process, goes to deadlock
- Block
- If it lock (wait able ) is release, or IO is completed, then goes to Ready
- Deadlock
- Exit (Zombie State)
- When process is finished, waiting for cleaning up
How Deadlock happen ?
- When process A has resource a, and it need resource b from process B.
- At the same time, process B need resource a from A
- Then those process gonna have deadlock due to both of them can get the resource they need.
Reference
https://slideplayer.com/slide/5219996/
想要看到更多瑋哥的學習筆記、考試複習資料、面試準備資料?想要看到IBM工做時期的技術積累和國外初創公司的經驗總結?
敬請關注:
瑋哥的博客 —— CSDN的傳送門
瑋哥的博客 —— 簡書的傳送門
瑋哥的博客 —— 博客園的傳送門