270 likes | 560 Views
CS 514 Operating Systems. User-Mode & Kernel Mode Threads Implementation and Properties. Department of Computer Science Southern Illinois University Edwardsville Spring, 2009 Dr. Hiroshi Fujinoki E-mail: hfujino@siue.edu. UK_Threads/000. Processes and Threads. Concept of threads.
E N D
CS 514 Operating Systems User-Mode & Kernel Mode Threads Implementation and Properties Department of Computer Science Southern Illinois University Edwardsville Spring, 2009 Dr. Hiroshi Fujinoki E-mail: hfujino@siue.edu UK_Threads/000
Processes and Threads Concept of threads How do threads solve the problem in processes? Two different thread implementations CS 514 Operating Systems Problems in processes UK_Threads/001
Processes and Threads CS 514 Operating Systems Problems in processes • High overhead in inter-process-communication (IPC) • High context-switching overhead in multitasking using processes UK_Threads/002
Processes and Threads Memory address space for each process P1 What if, some process need to share some information (data)? P2 P3 Processes exchange information through OS (IPC) OS Memory CS 514 Operating Systems Problems in processes • High overhead in inter-process-communication (IPC) • Processes can not access memory • address outside of its address space • “output redirection” • “pipe” • “semaphore” • “message passing” UK_Threads/003
Processes and Threads The high-overhead IPC’s are acceptable for loosely-coupled processes system call Memory address space for each process P1 P2 P3 Closely-coupled processes OS Memory CS 514 Operating Systems Problems in processes • High overhead in inter-process-communication (IPC) • Processes can not access memory • address outside of its address space What if, some process need to share some information (data)? Processes exchange information through OS (IPC) • Keyboard input • “output redirection” • Background spell-check • “pipe” • Automatic file-save • “semaphore” • “message passing” UK_Threads/004
Processes and Threads Processor P1 P2 P3 Registers Time PCB-P2 PCB-P3 Memory PCB-P1 CS 514 Operating Systems Problems in processes • High context-switching overhead in multitasking using processes SAVE LOAD OS UK_Threads/005
Processes and Threads The high-overhead IPC’s are acceptable for loosely-coupled processes Processor P1 P2 P3 Registers Time PCB-P3 PCB-P2 Memory PCB-P1 CS 514 Operating Systems Problems in processes • High context-switching overhead in multitasking using processes Closely-coupled processes • Keyboard input • Background spell-check • Automatic file-save LOAD SAVE OS UK_Threads/006
Processes and Threads Thread1 P1 Thread2 Process Thread3 P2 P3 OS OS Memory Memory CS 514 Operating Systems Concept of threads UK_Threads/007
Processes and Threads Global Variable Area P1 P2 P3 OS OS Memory Memory CS 514 Operating Systems Concept of threads Process Address Space Thread1 Thread2 Thread3 UK_Threads/008
Processes and Threads CS 514 Operating Systems How do threads solve the problem in processes? • High overhead in inter-process-communication (IPC) • High context-switching overhead in multitasking using processes UK_Threads/009
Processes and Threads Solved system call Inter-process communications must go through OS (system call) P1 P2 The member threads can access shared data w/out going through a system call P3 OS OS Memory Memory CS 514 Operating Systems How do threads solve the problem in processes? • High overhead in inter-process-communication (IPC) Thread1 Thread2 Thread3 UK_Threads/010
Processes and Threads TCB TCB TCB TCB PCB TCB is a subset of PCB CS 514 Operating Systems How do threads solve the problem in processes? • High context-switching overhead in multitasking using processes UK_Threads/011
Processes and Threads PCB TCB is a subset of PCB CS 514 Operating Systems How do threads solve the problem in processes? • High context-switching overhead in multitasking using processes TCB TCB TCB TCB UK_Threads/012
Processes and Threads PCB TCB is a subset of PCB CS 514 Operating Systems How do threads solve the problem in processes? • High context-switching overhead in multitasking using processes TCB TCB TCB TCB UK_Threads/013
Processes and Threads Solved PCB TCB is a subset of PCB CS 514 Operating Systems How do threads solve the problem in processes? • High context-switching overhead in multitasking using processes TCB TCB TCB TCB UK_Threads/014
Processes and Threads Where are “TCB’s”? PCB Processor P1 Thread1 Thread2 Process Registers P2 Thread3 P3 OS PCB-P3 PCB-P2 Memory Memory PCB-P1 CS 514 Operating Systems How do threads solve the problem in processes? • High context-switching overhead in multitasking using processes OS UK_Threads/015
Processes and Threads Kernel-Mode Threads Application-Mode Threads CS 514 Operating Systems Two different thread implementations • OS manages each thread • (as well as processes) Thread Implementation • OS has thread manager (scheduler) • A.K.A. “OS-mode threads” • OS does NOT manage each • thread (it manages only processes) • OS does not have thread manager • A.K.A. “user-mode threads” UK_Threads/016
Processes and Threads Application-Mode Threads Kernel-Mode Threads Process Scheduler Process Scheduler = PCB = TCB Thread Scheduler OS OS Memory Memory CS 514 Operating Systems Thread1 Thread1 Thread2 Thread2 Thread3 Thread3 UK_Threads/017
Processes and Threads Application-Mode Threads Kernel-Mode Threads Process Scheduler = PCB = TCB OS OS Memory Memory CS 514 Operating Systems Thread1 Thread1 Thread2 Thread2 Thread3 Thread3 Thread Scheduler Process Scheduler Thread Scheduler UK_Threads/018
Processes and Threads Application-Mode Threads Kernel-Mode Threads CS 514 Operating Systems System call Function call (faster than system call) Process T1 T2 Process T3 OS Process Thread Scheduler T1 Process T2 T3 OS UK_Threads/019