Download presentation
Presentation is loading. Please wait.
1
Threads: Light-Weight Processes
CS 314 Operating Systems Threads: Light-Weight Processes Department of Computer Science Southern Illinois University Edwardsville Spring, 2019 Dr. Hiroshi Fujinoki UK_Threads/000
2
CS 314 Operating Systems Processes and Threads Problems in processes
Concept of threads How do threads solve the problem in processes? Two different thread implementations UK_Threads/001
3
CS 314 Operating Systems Processes and Threads Problems in processes
High overhead in inter-process-communication (IPC) High context-switching overhead in multitasking using processes UK_Threads/002
4
CS 314 Operating Systems Processes and Threads Problems in processes
High overhead in inter-process-communication (IPC) Processes can not access memory address outside of its address space Memory address space for each process Memory P1 P2 P3 Data in Memory What if, some process need to share some information (data)? Processes exchange information through OS (IPC) “shared memory” “pipe” OS “semaphore” “message passing” UK_Threads/003
5
CS 314 Operating Systems Processes and Threads Problems in processes
High overhead in inter-process-communication (IPC) Processes can not access memory address outside of its address space Memory P1 P2 P3 What if, some process need to share some information (data)? move it to shared memory Processes exchange information through OS (IPC) Shared Memory OS performs this operation “shared memory” “pipe” OS “semaphore” “message passing” UK_Threads/003
6
CS 314 Operating Systems Processes and Threads Problems in processes
The high-overhead IPC’s are acceptable for loosely-coupled processes Problems in processes High overhead in inter-process-communication (IPC) Processes can not access memory address outside of its address space Memory address space for each process Memory P1 What if, some process need to share some information (data)? P2 P3 system call Processes exchange information through OS (IPC) Closely-coupled processes Keyboard input “shared memory” Background spell-check “pipe” OS Automatic file-save “semaphore” “message passing” UK_Threads/004
7
CS 314 Operating Systems Processes and Threads Problems in processes
High context-switching overhead in multitasking using processes Memory Processor P1 P2 Registers P3 SAVE LOAD Time PCB-P1 PCB-P2 PCB-P3 OS UK_Threads/005
8
CS 314 Operating Systems Processes and Threads Problems in processes
The high-overhead IPC’s are acceptable for loosely-coupled processes Problems in processes High context-switching overhead in multitasking using processes Closely-coupled processes Memory Keyboard input Processor P1 Background spell-check Automatic file-save P2 Registers P3 SAVE LOAD Time PCB-P1 PCB-P2 PCB-P3 OS UK_Threads/006
9
CS 314 Operating Systems Processes and Threads Concept of threads P1
Memory Memory OS P1 Thread1 Thread2 Thread3 Process P2 P3 OS UK_Threads/007
10
CS 314 Operating Systems Processes and Threads Concept of threads
Global Variable Area Concept of threads Memory Memory P1 Thread1 Process Address Space P2 Thread2 Thread3 P3 OS OS UK_Threads/008
11
CS 314 Operating Systems Processes and Threads
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
12
CS 314 Operating Systems Processes and Threads
Inter-process communications must go through OS (system call) The member threads can access shared data w/out going through a system call Processes and Threads Solved How do threads solve the problem in processes? High overhead in inter-process-communication (IPC) Memory OS P1 P2 P3 system call IPC by “message passing” Memory OS P1 P2 P3 Shared Memory move it to shared memory OS performs this operation IPC by “shared memory” Memory Thread1 Thread2 Thread3 OS UK_Threads/010
13
CS 314 Operating Systems PCB Processes and Threads
How do threads solve the problem in processes? High context-switching overhead in multitasking using processes PCB TCB TCB is a subset of PCB UK_Threads/011
14
CS 314 Operating Systems PCB Processes and Threads
How do threads solve the problem in processes? High context-switching overhead in multitasking using processes PCB TCB TCB TCB TCB TCB is a subset of PCB UK_Threads/012
15
CS 314 Operating Systems PCB Processes and Threads
How do threads solve the problem in processes? High context-switching overhead in multitasking using processes PCB TCB TCB TCB TCB TCB is a subset of PCB UK_Threads/013
16
CS 314 Operating Systems PCB Processes and Threads
Solved How do threads solve the problem in processes? High context-switching overhead in multitasking using processes PCB TCB User ID Total CPU time Total amount of memory TCB TCB TCB TCB is a subset of PCB UK_Threads/014
17
CS 314 Operating Systems Processes and Threads
How do threads solve the problem in processes? High context-switching overhead in multitasking using processes Memory Memory Where are “TCB’s”? P1 Thread1 Thread2 Thread3 Processor Registers Process P2 P3 PCB-P1 PCB-P2 PCB-P3 OS OS PCB UK_Threads/015
18
CS 314 Operating Systems Processes and Threads
Two different thread implementations Kernel-Mode Threads OS manages each thread (as well as processes) Thread Implementation OS has thread manager (scheduler) Application-Mode Threads 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
19
CS 314 Operating Systems Processes and Threads Thread1 Thread1 Thread2
Kernel-Mode Threads Application-Mode Threads Memory Memory Thread1 Thread1 Thread2 Thread2 Thread3 Thread3 Process Scheduler Process Scheduler OS OS Thread Scheduler = PCB = TCB UK_Threads/017
20
CS 314 Operating Systems Processes and Threads Thread1 Thread1 Thread2
Kernel-Mode Threads Application-Mode Threads Memory Memory Thread1 Thread1 Thread2 Thread2 Thread3 Thread3 Thread Scheduler Process Scheduler Process Scheduler OS OS Thread Scheduler = PCB = TCB UK_Threads/018
21
CS 314 Operating Systems Processes and Threads Process T1 T2 Process
System call Function call (faster than system call) Process T1 Kernel-Mode Threads T2 Process T3 OS Process Thread Scheduler T1 Process T2 Application-Mode Threads T3 OS UK_Threads/019
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.