1 Processes and Threads Chapter 2 2.1 Processes 2.2 Threads 2.3 Interprocess communication 2.4 Classical IPC problems 2.5 Scheduling.

Slides:



Advertisements
Similar presentations
1 Processes and Threads Creation and Termination States Usage Implementations.
Advertisements

1 Interprocess Communication 1. Ways of passing information 2. Guarded critical activities (e.g. updating shared data) 3. Proper sequencing in case of.
Scheduling Introduction to Scheduling
1 Processes and Threads Chapter Processes 2.2 Threads 2.3 Interprocess communication 2.4 Classical IPC problems 2.5 Scheduling.
Chapter 2 Processes and Threads
Pertemuan 13 Threads Matakuliah: H0483 / Network Programming Tahun: 2005 Versi: 1.0.
Operating Systems COMP 4850/CISG 5550 Processes Introduction to Threads Dr. James Money.
Cpr E 308 Spring 2004 Recap for Midterm Introductory Material What belongs in the OS, what doesn’t? Basic Understanding of Hardware, Memory Hierarchy.
1 Created by Another Process Reason: modeling concurrent sub-tasks Fetch large amount data from network and process them Two sub-tasks: fetching  processing.
Processes and Threads Chapter Processes 2.2 Threads 2.3 Interprocess communication 2.4 Classical IPC problems 2.5 Scheduling.
Review: Chapters 1 – Chapter 1: OS is a layer between user and hardware to make life easier for user and use hardware efficiently Control program.
1 Threads CSCE 351: Operating System Kernels Witawas Srisa-an Chapter 4-5.
Chapter 2: Processes Topics –Processes –Threads –Process Scheduling –Inter Process Communication (IPC) Reference: Operating Systems Design and Implementation.
Avishai Wool lecture Introduction to Systems Programming Lecture 4 Inter-Process / Inter-Thread Communication.
Avishai Wool lecture Priority Scheduling Idea: Jobs are assigned priorities. Always, the job with the highest priority runs. Note: All scheduling.
Page 1 Processes and Threads Chapter Processes 2.2 Threads 2.3 Interprocess communication 2.4 Classical IPC problems 2.5 Scheduling.
Ceng Operating Systems Chapter 2.5 : Threads Process concept  Process scheduling  Interprocess communication  Deadlocks  Threads.
1 Processes and Threads Chapter Processes 2.2 Threads 2.3 Interprocess communication 2.4 Classical IPC problems 2.5 Scheduling.
Introduction to Operating Systems – Windows process and thread management In this lecture we will cover Threads and processes in Windows Thread priority.
1 What is a Process ? The activity of program execution. Also called a task or job Has associated with it: Code Data Resources A State An executing set.
CMPT 300: Operating Systems Review THIS REIVEW SHOULD NOT BE USED AS PREDICTORS OF THE ACTUAL QUESTIONS APPEARING ON THE FINAL EXAM.
CSCE 351: Operating System Kernels
3.5 Interprocess Communication
Chapter 2 Processes and Threads Scheduling Classical Problems.
Chapter 2 Processes and Threads Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved
Race Conditions CS550 Operating Systems. Review So far, we have discussed Processes and Threads and talked about multithreading and MPI processes by example.
1 Interprocess Communication Race Conditions Two processes want to access shared memory at same time.
OPERATING SYSTEMS DESIGN AND IMPLEMENTATION Third Edition ANDREW S. TANENBAUM ALBERT S. WOODHULL Yan hao (Wilson) Wu University of the Western.
Processes and threads Processes Threads Scheduling
Processes (Διεργασίες)
Processes and Threads.
1 Process States (1) Possible process states –running –blocked –ready Transitions between states shown.
CS450/550 P&T.1 Adapted from MOS2E UC. Colorado Springs CS450/550 Operating Systems Lecture 2 Processes and Threads Palden Lama Department of Computer.
1 Processes Chapter Processes 2.3 Interprocess communication 2.4 Classical IPC problems 2.5 Scheduling.
MODERN OPERATING SYSTEMS Third Edition ANDREW S. TANENBAUM Chapter 2 Processes and Threads Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall,
1 Processes, Threads, Race Conditions & Deadlocks Operating Systems Review.
1 Scheduling The part of the OS that makes the choice of which process to run next is called the scheduler and the algorithm it uses is called the scheduling.
Cpr E 308 Spring 2004 Real-time Scheduling Provide time guarantees Upper bound on response times –Programmer’s job! –Every level of the system Soft versus.
1 Processes Management 1 Processes 2 Threads 3 IPC problems 4 Processes Scheduling 5 Deadlock.
ITEC 502 컴퓨터 시스템 및 실습 Chapter 2-1: Process Mi-Jung Choi DPNM Lab. Dept. of CSE, POSTECH.
Operating Systems Scheduling. Bursts of CPU usage alternate with periods of waiting for I/O. (a) A CPU-bound process. (b) An I/O-bound process. Scheduling.
ITFN 3601 Introduction to Operating Systems Lecture 3 Processes, Threads & Scheduling Intro.
OPERATING SYSTEMS DESIGN AND IMPLEMENTATION Third Edition ANDREW S. TANENBAUM ALBERT S. WOODHULL Yan hao (Wilson) Wu University of the Western.
1 Interprocess Communication (IPC) - Outline Problem: Race condition Solution: Mutual exclusion –Disabling interrupts; –Lock variables; –Strict alternation.
ITFN 2601 Introduction to Operating Systems Lecture 4 Scheduling.
1 Chapter 2.5 : Threads Process concept  Process concept  Process scheduling  Process scheduling  Interprocess communication  Interprocess communication.
CSE 153 Design of Operating Systems Winter 2015 Midterm Review.
Cs431-cotter1 Processes and Threads Tanenbaum 2.1, 2.2 Crowley Chapters 3, 5 Stallings Chapter 3, 4 Silberschaz & Galvin 3, 4.
Shahriar Pirnia Operating system سيستم عامل.
Processes and Threads MICROSOFT.  Process  Process Model  Process Creation  Process Termination  Process States  Implementation of Processes  Thread.
1 Processes and Threads Part II Chapter Processes 2.2 Threads 2.3 Interprocess communication 2.4 Classical IPC problems 2.5 Scheduling.
1 CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms Multiple-Processor Scheduling Real-Time Scheduling.
ITEC 502 컴퓨터 시스템 및 실습 Chapter 2-2: Threads Mi-Jung Choi DPNM Lab. Dept. of CSE, POSTECH.
操作系统原理 OPERATING SYSTEM Chapter 2 Processes and Threads 进程与线程.
1 Module 3: Processes Reading: Chapter Next Module: –Inter-process Communication –Process Scheduling –Reading: Chapter 4.5, 6.1 – 6.3.
7/9/ Realizing Concurrency using Posix Threads (pthreads) B. Ramamurthy.
Processes and Threads Chapter 3 and 4 Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,
Operating Systems Process Managment.
Interprocess Communication Race Conditions
Chapter 2 Processes and Threads Today 2.1 Processes 2.2 Threads
Chapter 2 Scheduling.
MODERN OPERATING SYSTEMS Third Edition ANDREW S
Implementing Threads in User Space
Operating Systems Chapter 2: Processes and Threads
Processes and Threads Part III
Chapter 2 Processes and Threads 2.1 Processes 2.2 Threads
Chapter 2 Processes and Threads 2.1 Processes 2.2 Threads
CS510 Operating System Foundations
Thread Model for Work Unit
Presentation transcript:

1 Processes and Threads Chapter Processes 2.2 Threads 2.3 Interprocess communication 2.4 Classical IPC problems 2.5 Scheduling

2 Agenda 2.1 Processes 2.2 Threads 2.3 Interprocess communication 2.4 Classical IPC problems 2.5 Scheduling

3 Process The most central concept in any OS An abstraction of a running program Modern Computers –Can do more than one thing at the same time Can run user programs Can read disk and work with user terminal –In a multiprogramming system More than one user program can be scheduled Each may run for tens of msecs.

4 Processes The Process Model Multiprogramming of four programs Conceptual model of 4 independent, sequential processes Only one program active at any instant

5 Process Creation Principal events that cause process creation 1.System initialization 2.Execution of a process creation system 3.User request to create a new process 4.Initiation of a batch job

6 Process Termination Conditions which terminate processes 1.Normal exit (voluntary) 2.Error exit (voluntary) 3.Fatal error (involuntary) 4.Killed by another process (involuntary)

7 Process Hierarchies Parent creates a child process, child processes can create its own process Forms a hierarchy –UNIX calls this a "process group" Windows has no concept of process hierarchy –all processes are created equal

8 Process States (1) Possible process states –running –blocked –ready Transitions between states shown

9 Process States (2) Lowest layer of process-structured OS –handles interrupts, scheduling Above that layer are sequential processes

10 Implementation of Processes (1) Fields of a process table entry

11 Implementation of Processes (2) Skeleton of what lowest level of OS does when an interrupt occurs

12 Agenda 2.1 Processes 2.2 Threads 2.3 Interprocess communication 2.4 Classical IPC problems 2.5 Scheduling

13 Threads In traditional OS, each process has –An address space –A single tread of control In modern OS, each process may have –Multiple threads of control –Same address spare –Running in quasi-parallel Thread or a Lightweight Process has –a program counter, registers, stack

14 Threads The Thread Model (1) (a) Three processes each with one thread (b) One process with three threads

15 The Thread Model (2) Items shared by all threads in a process Items private to each thread

16 The Thread Model (3) Each thread has its own stack

17 Thread Usage (1) A word processor with three threads

18 Thread Usage (2) A multithreaded Web server

19 Thread Usage (3) Rough outline of code for previous slide (a) Dispatcher thread (b) Worker thread

20 Thread Usage (4) Three ways to construct a server

21 Implementing Threads in User Space A user-level threads package

22 Implementing Threads in the Kernel A threads package managed by the kernel

23 Hybrid Implementations Multiplexing user-level threads onto kernel- level threads

24 Scheduler Activations Goal – mimic functionality of kernel threads –gain performance of user space threads Avoids unnecessary user/kernel transitions Kernel assigns virtual processors to each process –lets runtime system allocate threads to processors Problem: –Fundamental reliance on kernel (lower layer) –Calling procedures in user space (higher layer) Called upcall

25 Pop-Up Threads Creation of a new thread when message arrives (a) before message arrives (b) after message arrives

26 Making Single-Threaded Code Multithreaded (1) Conflicts between threads over the use of a global variable

27 Making Single-Threaded Code Multithreaded (2) Threads can have private global variables

28 Agenda 2.1 Processes 2.2 Threads 2.3 Interprocess communication 2.4 Classical IPC problems 2.5 Scheduling

29 Interprocess Communication Processes may need to communicate –E.g., output of one goes to input of the other one Issues –How to pass information different address spaces –Making critical activities Two process try to grab the last 1MB of memory –Proper sequencing One process is producing data for the other one

30 Interprocess Communication Race Conditions Two processes want to access shared memory at same time

31 Critical Regions (1) Critical Regions or Critical Sections –The part of the program where shared memory is accessed. Four conditions to provide mutual exclusion 1.No two processes simultaneously in critical region 2.No assumptions made about speeds or numbers of CPUs 3.No process running outside its critical region may block another process 4.No process must wait forever to enter its critical region

32 Critical Regions (2) Mutual exclusion using critical regions

33 Mutual Exclusion with Busy Waiting (0) Mutual Exclusion –Only one process can be in the critical section. Disabling Interrupts (HW Solution) –Dangerous: May lead to the end of the system Lock Variables (SW Solution) –Fatal Flow: Similar to Spooler Directory Strict Alternation (SW Solution) –Busy Waiting, Violating Condition 3 Peterson’s Solution (SW Solution) –Busy Waiting TSL Instruction (HW/SW Solution) –Busy Waiting, but Faster

34 Mutual Exclusion with Busy Waiting (1) Strict Alternation (SW Solution) Proposed solution to critical region problem (a) Process 0. (b) Process 1.

35 Mutual Exclusion with Busy Waiting (2) Peterson’s Solution (SW Solution)

36 Mutual Exclusion with Busy Waiting (3) Using TSL Instruction (HW/SW Solution) Entering and leaving a critical region using the TSL instruction

37 Mutual Exclusion with Sleep and Wakeup (0) Producer-Consumer Problem Priority Inversion Problem –busy waiting with priority! Solution with Fatal Race Condition –Waking up a consumer that is not asleep yet! Semaphore –An integer that counts the number of wake-up calls. Mutexes – Binary semaphores, good for mutual exclusion. Monitors –Easier to program (Synchronized in Java). Message Passing –N messages used for communication coordination. Barriers –Synchronization of N processes/threads.

38 Mutual Exclusion with Sleep and Wakeup (1) Fatal Race Condition

39 Mutual Exclusion with Sleep and Wakeup (2) Using Semaphores

40 Mutual Exclusion with Sleep and Wakeup (3) Using Mutexes Implementation of mutex_lock and mutex_unlock

41 Mutual Exclusion with Sleep and Wakeup (4) Using Monitors (1) Example of a monitor

42 Outline of producer-consumer problem with monitors –only one monitor procedure active at one time –buffer has N slots Mutual Exclusion with Sleep and Wakeup (4) Using Monitors (2)

43 Solution to producer-consumer problem in Java (part 1) Mutual Exclusion with Sleep and Wakeup (4) Using Monitors (3)

44 Solution to producer-consumer problem in Java (part 2) Mutual Exclusion with Sleep and Wakeup (4) Using Monitors (4)

45 The producer-consumer problem with N messages Mutual Exclusion with Sleep and Wakeup (5) Message Passing

46 Barriers Use of a barrier –processes approaching a barrier –all processes but one blocked at barrier –last process arrives, all are let through

47 Agenda 2.1 Processes 2.2 Threads 2.3 Interprocess communication 2.4 Classical IPC problems 2.5 Scheduling

48 Dining Philosophers (1) Philosophers eat/think Eating needs 2 forks Pick one fork at a time How to prevent deadlock

49 Dining Philosophers (2) A nonsolution to the dining philosophers problem

50 Dining Philosophers (3) Solution to dining philosophers problem (part 1)

51 Dining Philosophers (4) Solution to dining philosophers problem (part 2)

52 The Readers and Writers Problem A solution to the readers and writers problem

53 The Sleeping Barber Problem (1)

54 The Sleeping Barber Problem (2) Solution to sleeping barber problem.

55 Agenda 2.1 Processes 2.2 Threads 2.3 Interprocess communication 2.4 Classical IPC problems 2.5 Scheduling

56 Scheduling Scheduler –The part of the OS that make the choice of which process to run next. Scheduling Algorithm –The algorithm used for scheduling

57 Scheduling Introduction to Scheduling (1) Bursts of CPU usage alternate with periods of I/O wait –a CPU-bound process: spends most of its time on computing –an I/O bound process: spends most of its time waiting for I/O

58 Introduction to Scheduling (2) System Algorithm Goals

59 Scheduling Algorithm Goals Throughput –The number of jobs per hour that the system completes. Turnaround time –The statically average time from the moment that a batch job is submitted until the moment it is completed.

60 Scheduling in Batch Systems (1) First-Come First-Served Shortest Job First (non-preemptive) –An example of shortest job first scheduling Shortest Remaining Time First (preemptive) Three-Level Scheduling

61 Scheduling in Batch Systems (2) Three level scheduling

62 Scheduling in Interactive Systems (1) Round Robin Scheduling –list of runnable processes –list of runnable processes after B uses up its quantum Priority Scheduling Multiple Queues Shortest Process Next Guaranteed Scheduling Lottery Scheduling Fair-Share Scheduling

63 Scheduling in Interactive Systems (2) A scheduling algorithm with four priority classes

64 Scheduling in Real-Time Systems Schedulable real-time system Given –m periodic events –event i occurs within period P i and requires C i seconds Then the load can only be handled if

65 Policy versus Mechanism Separate what is allowed to be done with how it is done –a process knows which of its children threads are important and need priority Scheduling algorithm parameterized –mechanism in the kernel Parameters filled in by user processes –policy set by user process

66 Thread Scheduling (1) Possible scheduling of user-level threads 50-msec process quantum threads run 5 msec/CPU burst

67 Thread Scheduling (2) Possible scheduling of kernel-level threads 50-msec process quantum threads run 5 msec/CPU burst