Threads. Threads The Thread Model (1) CSCE 351: Operating System Kernels Witawas Srisa-an Chapter 4-5

Similar documents
Processes The Process Model. Chapter 2. Processes and Threads. Process Termination. Process Creation

Processes The Process Model. Chapter 2 Processes and Threads. Process Termination. Process States (1) Process Hierarchies

Chapter 2 Processes and Threads

Chapter 2 Processes and Threads. Interprocess Communication Race Conditions

CS450/550 Operating Systems

CS450/550 Operating Systems

Processes Prof. James L. Frankel Harvard University. Version of 6:16 PM 10-Feb-2017 Copyright 2017, 2015 James L. Frankel. All rights reserved.

PROCESSES & THREADS. Charles Abzug, Ph.D. Department of Computer Science James Madison University Harrisonburg, VA Charles Abzug

SYNCHRONIZATION M O D E R N O P E R A T I N G S Y S T E M S R E A D 2. 3 E X C E P T A N D S P R I N G 2018

Midterm Exam. October 20th, Thursday NSC

C09: Process Synchronization

PROCESS SYNCHRONIZATION

OPERATING SYSTEMS DESIGN AND IMPLEMENTATION Third Edition ANDREW S. TANENBAUM ALBERT S. WOODHULL. Chap. 2.2 Interprocess Communication

CSCI-GA Operating Systems Lecture 3: Processes and Threads -Part 2 Scheduling Hubertus Franke

Synchronization. CSE 2431: Introduction to Operating Systems Reading: Chapter 5, [OSC] (except Section 5.10)

Review. Preview. Three Level Scheduler. Scheduler. Process behavior. Effective CPU Scheduler is essential. Process Scheduling

What are they? How do we represent them? Scheduling Something smaller than a process? Threads Synchronizing and Communicating Classic IPC problems

Subject: Operating System (BTCOC403) Class: S.Y.B.Tech. (Computer Engineering)

Main Points of the Computer Organization and System Software Module

Synchronization COMPSCI 386

Modern Computers often do lots of things at the same time (web servers, accessing disks, background processes waiting for s,...).

CSE 153 Design of Operating Systems

Chapter 5 Concurrency: Mutual Exclusion. and. Synchronization. Operating Systems: Internals. and. Design Principles

ENGR 3950U / CSCI 3020U UOIT, Fall 2012 Quiz on Process Synchronization SOLUTIONS

STUDENT NAME: STUDENT ID: Problem 1 Problem 2 Problem 3 Problem 4 Problem 5 Total

CSC Operating Systems Spring Lecture - XII Midterm Review. Tevfik Ko!ar. Louisiana State University. March 4 th, 2008.

Concurrency and Synchronisation

Learning Outcomes. Concurrency and Synchronisation. Textbook. Concurrency Example. Inter- Thread and Process Communication. Sections & 2.

Department of Computer applications. [Part I: Medium Answer Type Questions]

148 PROCESSES CHAP. 2

Concurrency and Synchronisation

CHAPTER NO - 1 : Introduction:

Operating Systems. Designed and Presented by Dr. Ayman Elshenawy Elsefy

Threading and Synchronization. Fahd Albinali

STUDENT NAME: STUDENT ID: Problem 1 Problem 2 Problem 3 Problem 4 Problem 5 Total

Interprocess Communication and Synchronization

Motivation of Threads. Preview. Motivation of Threads. Motivation of Threads. Motivation of Threads. Motivation of Threads 9/12/2018.

Interprocess Communication By: Kaushik Vaghani

Chapter 5 Concurrency: Mutual Exclusion and Synchronization

CS370 Operating Systems

CS 153 Design of Operating Systems Winter 2016

Operating Systems Comprehensive Exam. Spring Student ID # 3/16/2006

Operating Systems. Operating Systems Summer 2017 Sina Meraji U of T

Lecture 9: Midterm Review

8: Scheduling. Scheduling. Mark Handley

Processes and Threads

What is the Race Condition? And what is its solution? What is a critical section? And what is the critical section problem?

Running. Time out. Event wait. Schedule. Ready. Blocked. Event occurs

CS370 Operating Systems Midterm Review

Concurrency. Chapter 5

Dealing with Issues for Interprocess Communication

CS 370 Operating Systems

CS 333 Introduction to Operating Systems. Class 3 Threads & Concurrency. Jonathan Walpole Computer Science Portland State University

Learning Outcomes. Processes and Threads. Major Requirements of an Operating System. Processes and Threads

UNIT 2 Basic Concepts of CPU Scheduling. UNIT -02/Lecture 01

Introduction to Real-Time Operating Systems

Semaphore. Originally called P() and V() wait (S) { while S <= 0 ; // no-op S--; } signal (S) { S++; }

Tasks. Task Implementation and management

Chapter 6: Synchronization. Operating System Concepts 8 th Edition,

Process Management And Synchronization


Operating Systems. Lecture 4 - Concurrency and Synchronization. Master of Computer Science PUF - Hồ Chí Minh 2016/2017

Remaining Contemplation Questions

Processes and Threads

COMP SCI 3SH3: Operating System Concepts (Term 2 Winter 2006) Test 2 February 27, 2006; Time: 50 Minutes ;. Questions Instructor: Dr.

CS 333 Introduction to Operating Systems. Class 3 Threads & Concurrency. Jonathan Walpole Computer Science Portland State University

Problem Set 2. CS347: Operating Systems

Unit I. Chapter 2: Process and Threads

UNIT:2. Process Management

CS 571 Operating Systems. Midterm Review. Angelos Stavrou, George Mason University

Operating Systems: Quiz2 December 15, Class: No. Name:

CS153: Midterm (Fall 16)

Overview. Thread Packages. Threads The Thread Model (1) The Thread Model (2) The Thread Model (3) Thread Usage (1)

Preview. Process Scheduler. Process Scheduling Algorithms for Batch System. Process Scheduling Algorithms for Interactive System

IT 540 Operating Systems ECE519 Advanced Operating Systems

Process Synchronization: Semaphores. CSSE 332 Operating Systems Rose-Hulman Institute of Technology

Course Syllabus. Operating Systems

Processes and Threads. Processes: Review

AC59/AT59/AC110/AT110 OPERATING SYSTEMS & SYSTEMS SOFTWARE DEC 2015

EECS 482 Introduction to Operating Systems

Dr. Rafiq Zakaria Campus. Maulana Azad College of Arts, Science & Commerce, Aurangabad. Department of Computer Science. Academic Year

Operating Systems (1DT020 & 1TT802)

CS 333 Introduction to Operating Systems. Class 4 Concurrent Programming and Synchronization Primitives

Semaphores. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

1.1 CPU I/O Burst Cycle

Maximum CPU utilization obtained with multiprogramming. CPU I/O Burst Cycle Process execution consists of a cycle of CPU execution and I/O wait

Operating Systems Comprehensive Exam. Spring Student ID # 2/17/2011

CPU Scheduling. CSE 2431: Introduction to Operating Systems Reading: Chapter 6, [OSC] (except Sections )

7: Interprocess Communication

Introduction to Operating Systems

2 Threads vs. Processes

Concurrency: a crash course

MARUTHI SCHOOL OF BANKING (MSB)

Techno India Batanagar Department of Computer Science & Engineering. Model Questions. Multiple Choice Questions:

CISC 7310X. C05: CPU Scheduling. Hui Chen Department of Computer & Information Science CUNY Brooklyn College. 3/1/2018 CUNY Brooklyn College

Chapter 5 Asynchronous Concurrent Execution

Chapter 6: Process Synchronization

This slide show uses materials from the Windows Operating System Internals Curriculum Development Kit

Recap: Thread. What is it? What does it need (thread private)? What for? How to implement? Independent flow of control. Stack

Preview. The Thread Model Motivation of Threads Benefits of Threads Implementation of Thread

Transcription:

Threads CSCE 351: Operating System Kernels Witawas Srisa-an Chapter 4-5 1 Threads The Thread Model (1) (a) Three processes each with one thread (b) One process with three threads 2 1

The Thread Model (2) Items shared by all threads in a process Items private to each thread 3 The Thread Model (3) Each thread has its own stack 4 2

Thread Usage (1) A word processor with three threads 5 Thread Usage (2) A multithreaded Web server 6 3

Thread Usage (3) Rough outline of code for previous slide (a) Dispatcher thread (b) Worker thread 7 Thread Usage (4) Three ways to construct a server 8 4

Implementing Threads in User Space A user-level threads package 9 Implementing Threads in the Kernel A threads package managed by the kernel 10 5

Hybrid Implementations Multiplexing user-level threads onto kernellevel threads 11 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) 12 6

Pop-Up Threads Creation of a new thread when message arrives (a) before message arrives (b) after message arrives 13 Making Single-Threaded Code Multithreaded (1) Conflicts between threads over the use of a global variable 14 7

Making Single-Threaded Code Multithreaded (2) Threads can have private global variables 15 Interprocess Communication Race Conditions Two processes want to access shared memory at same time 16 8

Critical Regions (1) 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 17 Critical Regions (2) Mutual exclusion using critical regions 18 9

Mutual Exclusion with Busy Waiting (1) Proposed solution to critical region problem (a) Process 0. (b) Process 1. No process running outside its critical region may block another process 19 Mutual Exclusion with Busy Waiting (2) Peterson's solution 20 10

Mutual Exclusion with Busy Waiting (3) Entering and leaving a critical region using the TSL instruction 21 Sleep and Wakeup Producer-consumer problem with fatal race condition 22 11

Semaphores A variable type 0 or any positive values (counting) 0 or 1 (binary) Support two operations down (p) if value > 0 then decrement if value = 0 then suspend process without completing the down indivisible atomic action up (v) increment the semaphore value and if there are processes sleeping on the semaphore, wake one of them 23 up Semaphore arena queue 24 12

Semaphores The producer-consumer problem using semaphores 25 Mutexes Implementation of mutex_lock and mutex_unlock 26 13

suspend.c and wake.c Example Program 27 Monitors Language construct higher level synchronization primitive Only one process can be active in a monitor at any instant Use condition variables to block processes wait operation signal operation 28 14

Monitors (1) Example of a monitor 29 Monitors (2) Outline of producer-consumer problem with monitors only one process can be active in a monitor at one time buffer has N slots 30 15

The Readers and Writers Problem A solution to the readers and writers problem 31 The Sleeping Barber Problem (1) 32 16

The Sleeping Barber Problem (2) Solution to sleeping barber problem. 33 Scheduling Introduction to Scheduling (1) Bursts of CPU usage alternate with periods of I/O wait a CPU-bound process an I/O bound process 34 17

Introduction to Scheduling (2) Scheduling Algorithm Goals 35 Scheduling in Batch Systems (1) (8 + 12 + 16 + 20) / 4 = 14 units (4 + 8 + 12 + 20) / 4 = 11 units An example of shortest job first scheduling 36 18

Scheduling in Batch Systems (2) Three level scheduling 37 Scheduling in Interactive Systems (1) Round Robin Scheduling list of runnable processes list of runnable processes after B uses up its quantum 38 19

Scheduling in Interactive Systems (2) A scheduling algorithm with four priority classes 39 Scheduling in Real-Time Systems (1) 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 m " i= 1 Ci P i! 1 40 20

Scheduling in Real-Time Systems (2) Example four periodic events: 100, 200, 400, 600 ms required CPU times: 25, 40, 100, 120 ms Is this system schedulable? 41 Thread Scheduling (1) Possible scheduling of user-level threads 50-msec process quantum threads run 5 msec/cpu burst 42 21

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