Download presentation
Presentation is loading. Please wait.
Published byLorin Goodwin Modified over 9 years ago
1
Chapter 2 (PART 1) Light-Weight Process (Threads) Department of Computer Science Southern Illinois University Edwardsville Summer, 2004 Dr. Hiroshi Fujinoki E-mail: hfujino@siue.edu CS 414 Operating Systems Threads/001
2
CS 414 Operating Systems Threads/002 Presentation Agenda Two inefficiency problems in “process” The two problems motivate “light-weigh process” (“Light-weight process” = “Thread”) Introduce “thread” as a solution for the two problems in “process” How thread works?
3
CS 414 Operating Systems Threads/003 Structure of process PCB Address Space Stack Code Heap For some applications, this structure gives problems Assume an application program that (1) Requires multiple processes to execute an application program (2) Requires inter-process communications
4
BBS Server Host Implementation CS 414 Operating Systems Threads/004 Example Network BBS Server BBS DB Client A Client B Client C Client D BBS DB Client A Client B Client C Process A Process B Process C Multiprogramming
5
CS 414 Operating Systems Threads/005 Two inefficiency problems using processes in this BBS Server Context-switching overhead - When a context-switch happens, an entire PCB of the running process has to be saved and the one for the next has to be loaded. System call overhead in accessing shared information - In order for the BBS information to be shared, the shared information needs to be in a different address space - To access data in a different address space, each process needs to call a system call
6
CS 414 Operating Systems Threads/006 Problem 1: Overhead for context switching Process A Process B Process C Client B arrives Client A arrives Running Ready What if the number of concurrent clients increased? Running Client C arrives Ready Running Context-switching overhead
7
CS 414 Operating Systems Threads/007 Problem 1: Overhead for context switching (continued) If we just increase the number of clients, what will happen? Process A Process B Process C Process D Process E Running Ready Running Ready Running Ready Running Ready Running Ready Non-responding interval
8
CS 414 Operating Systems Threads/008 Problem 1: Overhead for context switching (continued) What could we do to reduce non-responding interval? Process A Process B Process C Process D Process E Running Ready Running Ready Running Ready Running This causes another problem Effective CPU goes down Non-responding interval
9
CS 414 Operating Systems Threads/009 Problem 2: System call overhead in accessing shared information BBS Server Host BBS DB Client A Client B Client C Process A Process B Process C Multiprogramming Process A Process C Process B BBS DB (Shared data) OS
10
CS 414 Operating Systems Threads/010 Two inefficiency problems using processes in this BBS Server - If number of clients is increased Context-switching overhead System call overhead in accessing shared information Either response time or effective CPU utilization is sacrificed - Shared data is implemented with another address space Slower program execution Light-weight process (thread) is a solution for the two problems
11
One Address Space CS 414 Operating Systems Threads/011 Concepts of light-weight process Multiple execution paths in a process Thread PCB A Address Space Process A PCB B Address Space Process B PCB C Address Space Process C PCB X Global Stack Global Heap Global PCB
12
Process CS 414 Operating Systems Threads/012 Concepts of light-weight process PCB A Address Space Process A PCB B Address Space Process B PCB C Address Space Process C PCB X Global Stack Global Heap Global PCB Private Stack Code Private Heap Private PCB
13
CS 414 Operating Systems Threads/013 Concepts of light-weight process PCB A Address Space Process A PCB B Address Space Process B PCB C Address Space Process C Process PCB X Global Stack Global Heap Private Stack Code Private Heap Private PCB Global PCB PCB N = Global PCB + Private PCB
14
CS 414 Operating Systems Threads/014 Concepts of light-weight process PCB w/out thread support Global PCB Private PCB When a CPU needs to be switched from a thread to another, only this part should be swapped Remaining Question: How context-switching overhead can be reduced?
15
CS 414 Operating Systems Threads/015 Concepts of light-weight process PCB w/out thread support Global PCB Private PCB When a CPU needs to be switched from a thread to another, only this part should be swapped For CPU switching between threads, global PCB remains remains same
16
CS 414 Operating Systems Threads/016 Definition of Threads Thread = Multi-threading - Making multiple threads in ready state - Similar to “multi-programming” - Much less overhead for context-switching and communication Multiple execution paths within a process “light-weight process”
17
CS 414 Operating Systems Threads/017 Major Advantages in threads Thread reduces context-switching and inter-process communication overhead (thus “light-weight”). The general advantages in threads are: - Share all resources assigned to a “process” Files opened, I/O devices assigned, global memory allocated, etc. - Ability to execute multiple different tasks in asynchronous way With easy and fast inter-thread communication
18
CS 414 Operating Systems Threads/018 Major Disadvantages in threads No memory protection between threads Managing assigned I/O resources could be very complex - Any thread in a process can use any resources assigned to a process - Multiple threads can be executed in any order Example Implementation of threads is not standardized - Each major OS (Solaris, LINUX, BSD, Windows) has its own implementation of threads and all different Programmers are responsible for avoiding “illegal access”
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.