운영체제

4 Thread

2021. 4. 9. 16:22

Thread

- Basic unit of CPU utilization(효율성)

- 같은 process내에서의 thread끼리는 자원을 공유한다 (code section, data section 등)

- 자원 공유의 Benefits

  1. Responsiveness(반응성) : process를 여러 스레드로 나누면 process의 일부가 block 되어도 다른 스레드로 동작 가능하다.

  2. Resource sharing(자원 공유) : 효율은 높이고, 메모리 낭비는 줄인다.

  3. Economy(경제적 측면) : context-switch time (PCB정보 업데이트 시간)이 소모되지 않음.

  4. Scalability(확장성) : multiprocessor 구조의 이점

- Multithread process 그림 (ppt 4)

 

Multicore Programming

- Concurrency (동시성)

- Parallelism (병렬성) ; 1개 이상의 task가 동시에 돌아간다.

  병렬화의 종류 : 1. Data parallelism  2. Task parallelism (ppt 7)

- Multicore, multiprocessor 시스템 사용 시 고려사항 (ppt 6)

- 스레드의 개수가 증가하면 하드웨어 구조의 support가 필요하다.

- Amdahl's Law : (수식 삽입 어떻게 하는지 모르겠다.. ppt 7 공식 참조)

 

Multithreading Models

1. User thread : managed by user level thread library (Win32 thread, Jave thread 등)

2. Kernel thread : managed and supported directly by the operating system(kernel) (Linux, Mac OS X 등)

- Thread Library : 스레드를 만들고 관리하기 위한 API 제공 (Pthread, Java Thread 등)

 

<Three models +a>

  1. Many-to-One model : Many user-level threads are mapped to a single kernel thread (ppt 12)

     문제점 : kernel-thread가 한 개라서 하나라도 block이 발생하면 전체 block이 일어난다.

  2. One-to-One model : Each user-level thread maps to kernel thread (ppt 13)

     문제점 : kernel thread를 create 하는데 overhead가 발생할 수 있다.

  3. Many-to-Many model : many user-level thread to be mapped to a smaller of equal number of kernel thread (ppt 14) -> 앞의 두 모델의 단점을 보완한 형태

  4. Two-level model : Many-to-Many + One-to-One 방식 (ppt 15) -> multithread기반의 multiprocessing기반 multiprogramming 가능

 

- Implicit Threading (ppt 16)

- Multithreading Issues (ppt 17)

 

User level threads vs. Kernel level thread

User Level Thread Kernel Level Thread
Faster to create and manage Slower to create and manage
user level의 thread library에서 실행한다 O/S가 kernel thread를 실행하고 지원한다.
user level thread는 어떤 O/S환경에서도 run 할 수 있다. 특정 O/S에서만 동작 가능하다
다중스레드 응용프로그램은 다중처리를 이용할 수 없다. kernel routin자체는 다중스레드가 될 수 있다.