0416 OS 수업 노트 (ch4.1)

Ji·2021년 4월 16일
0

Two types of threads

  • User Threads
    • Thread management done by user-level threads library / 사용자 공간에서 thread 라이브러리를 통해 제공. Kernel 지원 없이 thread 생성, 스케줄링, 관리 제공
  • Kernel Threads
    • Supported by the Kernel : The threads are supported and managed directly by the OS / OS가 직접 지원. Kernel이 쓰레드 생성, 스케줄링, 관리를 담당.

Multithreading Models

Many-to-One(다대일 모델)

  • Many user-level threads mapped to single kernel thread / 여러개의 User thread가 kernel thread로 매핑됨.
    -> thread 관리가 user 모드에서 이루어짐: 처리속도 빠름 but 하나의 thread가 block되면 전체의 process가 block 됨.

One-to-One (일대일 모델)

  • 각 user thread가 하나의 kernel thread에 mapping 됨
    ->하나의 thread가 blcok 돼도 나머지 thread는 동작 but 비용이 비쌈. (ex) windows XP/2000, Linux..

Many-to-Many Model (다대다 모델)

  • Allows many user level threads to be mapped to smaller or equal kernel threads / 여러 user thread가 그보다 적은 혹은 같은 kernel thread에 mapping. -> 비용은 일대일 모델보다 저렴. 스레드가 동시 수행 가능

Two-level Model

  • One popular variation on many-to-many model /다대다 모델과 비슷한 구조. user thread에 kernel thread를 제공 가능 ->점유율이 높아야 할 user thread에게 선점권을 부여 가능함

Thread library

  • 프로그래머에게 스레드를 생성/관리하기 위한 API (API: 응용 프로그램에서 사용할 수 있도록, 운영 체제나 프로그래밍 언어가 제공하는 기능을 제어할 수 있게 만든 인터페이스) 를 제공. thread library 제공을 위해선 2가지 방법이 존재.
  1. to provide a library entirely in user space with no kernel support./ 커널 지원 없이 사용자 공간에만 library 제공.
  2. to implement a kernel-level library supported by OS / OS에 의해 지원되는 커널 수준의 library를 구현

Threading Issues


(cf) System call

fork() system call: 새로운 프로세스를 생성 할 때 사용
wait() system call: 자식 프로세스가 끝날때 까지 기다릴 때 사용
getpid() system call: 현재 프로세스의 id 를 가져옴
getppid() system call: 부모 프로세스의 id(parent pid) 를 가져옴

  • fork() system call is used to create a new separate,
    duplicate process. / fork 의 결과는 프로세스 하나가 더 생김
  • exec() : 생성되는 새로운 프로세스는 없음. exec()를 호출한 프로세스의 PID가 그대로 새로운 프로세스에 적용됨. 따라서 exec()를 호출한 프로세스는 새 프로세스에 의해 덮어 씌이게 됨.

Thread Cancellation 스레드 취소 (중요)

  • Thread Cancellation: terminating a thread before it has finished by other threads

    -Asynchronous cancellation (비동기 취소) : terminate thread immediately / 취소 요청시 즉시 처리 시도
    -Deferred cancellation(지연 취소) : allows the target thread to periodically check if it should be cancelled. /
    target thread가 주기적으로 자신이 강제 종료되어야 할지를 체크함

Signal handling (중요)

  • Signal: 특정 이벤트가 발생 했을 때, 커널에서 프로세스로 신호를 보내서 알려주는 것
  • Signal Handler: 어떤 시그널을 받았을 때, 특정 동작을 하도록 사용자가 정의할 수 있음. 사용자가 코드를 만들어서 함수로 지정.
  • Signal Handling -> signals are used to notify a process that a particular event has occurred

    Two types of Signals
    -synchronous signal(illegal memory access, division by 0)
    -asynchronous signal(ctrl+c, timer expire)

Thread Pools

  • 스레드풀: 스레드를 미리 만들어놓은 풀장(??)

Signal 교수님 정리



Summary

profile
공부방

0개의 댓글