위 포스트는 udacity 의 Introduce to Operating Systems by Geogia Tech 를 참고하였습니다.
추가로 이 곳 을 참고하였습니다.
1) Thread
1-1. Preview
-
Process : Can only access one cpu core
-
Thread를 이용하면 multiple access cpu with single process가 가능하다!
앞으로 배울 것.
-
thread가 무엇?
-
thread와 프로세스가 다른점?
-
thread를 다루고, 만들기 위한 자료구조
1-2. Overview
Thread
-
an active entity
- executing a unit of behalf of a processes
-
works simultaneously with others
-
many threads executing ( concurrency )
=> 현대 운영체제 시스템에서는, 여러 쓰레드를 동시에 작동시키는 경우가 많음.
=> coordination이 좀 필요함.
-
-
requires coordination
(especially when multiple workers are working at same time and perhaps even contributing same toy order)
-
some restriction ex) sharing of I/O devices, cpu call, memory
어떤 쓰레드가 이걸 이용할 수 있을지를 정해줘야함.
-
1-3. Process vs Thread
1. Process의 구성
-
single thread process is represented by address space
=> virtual to physical mapping, code, file,…
-
execution context -> register, stack point to process counter
2. Thread의 구성
Thread : Multiple independent execution context
-
same part of virtual address space
=> share all virtual mapping, code, file…
-
execute different instruction & different access portion of address space & different input
=> Each thread needs stack point, program counter, stack, register…
=> separate data structure to represent per thread information
-
PCB will be more complex structure
=> shared among all threads & also have separate information about every single one of execution context that are part of process
1-4. Benefits of Multithreading
the advantages of using thread compared to multiprocessor & multi core system
-
Structure
Single process and multiple thread in the PCB
- share virtual address -> memory efficient
- indivisually has execution context such as process counter, register, stack pointer…
-
Running
-
Input matrix consist of input contexts of each process
=> parallelzing program has benefit on speed
-
they conduct exact same code but, not neccessary executing same instruction
-
their still need to have on private copy on stack pointer
-
-
Specialization
ex)
- different thread can manage different customer request
-
Give higher priority to those threads -> to manage more important requests
- each small portion of thread are running repeatedly -> their information can be stored cache -> hot cache
-
another issue
-
not required as many swap from disk compared to a multi-processed alterntve (이부분은 이해를 해야할듯!)
-
Inter process communication will be easy
because they share virtual addresses. so, we don’t need to estabilish transfer buffer or memory mapping
(communicating data & passing data among the processes or synchronizing among processes needs IPC)
-
1-5. Benefits of Multithreading - Single CPU
Are threads useful on a single CPU? or when (# of threads) > (# of CPUs)?
ex) Single Thread T1 make request move