1 Threads CSCE 351: Operating System Kernels Witawas Srisa-an Chapter 4-5.

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.
1 Processes and Threads Chapter Processes 2.2 Threads 2.3 Interprocess communication 2.4 Classical IPC problems 2.5 Scheduling.
1 Implementations: User-level Kernel-level User-level threads package each u.process defines its own thread policies! flexible mgt, scheduling etc…kernel.
Chapter 2 Processes and Threads
EEE 435 Principles of Operating Systems Interprocess Communication Pt II (Modern Operating Systems 2.3)
CSC 322 Operating Systems Concepts Lecture - 8: by Ahmed Mumtaz Mustehsan Special Thanks To: Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall,
Interprocess Communication
Pertemuan 13 Threads Matakuliah: H0483 / Network Programming Tahun: 2005 Versi: 1.0.
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.
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.
Synchronization Principles. Race Conditions Race Conditions: An Example spooler directory out in 4 7 somefile.txt list.c scores.txt Process.
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.
1 Race Conditions/Mutual Exclusion Segment of code of a process where a shared resource is accessed (changing global variables, writing files etc) is called.
OPERATING SYSTEMS DESIGN AND IMPLEMENTATION Third Edition ANDREW S. TANENBAUM ALBERT S. WOODHULL Yan hao (Wilson) Wu University of the Western.
1 Processes and Threads Chapter Processes 2.2 Threads 2.3 Interprocess communication 2.4 Classical IPC problems 2.5 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.
Scheduling Chap 2. Scheduling Introduction to Scheduling (1) Bursts of CPU usage alternate with periods of I/O wait –a CPU-bound process –an I/O bound.
1 Processes Chapter Processes 2.3 Interprocess communication 2.4 Classical IPC problems 2.5 Scheduling.
10/16/ Realizing Concurrency using the thread model B. Ramamurthy.
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.
B. RAMAMURTHY 10/24/ Realizing Concurrency using the thread model.
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.
Chapter 1 Computer System Overview Sections 1.1 to 1.6 Instruction exe cution Interrupt Memory hierarchy Cache memory Locality: spatial and temporal Problem.
1 Processes Management 1 Processes 2 Threads 3 IPC problems 4 Processes Scheduling 5 Deadlock.
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.
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.
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 سيستم عامل.
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 进程与线程.
B. RAMAMURTHY 5/10/2013 Amrita-UB-MSES Realizing Concurrency using the thread model.
7/9/ Realizing Concurrency using Posix Threads (pthreads) B. Ramamurthy.
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee.
Realizing Concurrency using the thread model
Interprocess Communication Race Conditions
Realizing Concurrency using the thread model
MODERN OPERATING SYSTEMS Third Edition ANDREW S
Realizing Concurrency using Posix Threads (pthreads)
Realizing Concurrency using the thread model
Implementing Threads in User Space
Operating Systems Chapter 2: Processes and Threads
Realizing Concurrency using the thread model
Processes and Threads Part III
Chapter 2 Processes and Threads 2.1 Processes 2.2 Threads
Operating Systems Threads 1.
Realizing Concurrency using the thread model
Realizing Concurrency using Posix Threads (pthreads)
Realizing Concurrency using the thread model
Realizing Concurrency using Posix Threads (pthreads)
Thread Model for Work Unit
What is a Thread? A thread is similar to a process, but it typically consists of just the flow of control. Multiple threads use the address space of a.
Presentation transcript:

1 Threads CSCE 351: Operating System Kernels Witawas Srisa-an Chapter 4-5

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

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

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

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

6 Thread Usage (2) A multithreaded Web server

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

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

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

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

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

12 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)

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

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

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

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

17 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

18 Critical Regions (2) Mutual exclusion using critical regions

19 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

20 Mutual Exclusion with Busy Waiting (2) Peterson's solution

21 Mutual Exclusion with Busy Waiting (3) Entering and leaving a critical region using the TSL instruction

22 Sleep and Wakeup Producer-consumer problem with fatal race condition

23 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 up

24 Semaphore arena … queue

25 Semaphores The producer-consumer problem using semaphores

26 Mutexes Implementation of mutex_lock and mutex_unlock

27 Example Program suspend.c and wake.c

28 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

29 Monitors (1) Example of a monitor

30 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

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

32 The Sleeping Barber Problem (1)

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

34 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

35 Introduction to Scheduling (2) Scheduling Algorithm Goals

36 Scheduling in Batch Systems (1) An example of shortest job first scheduling ( ) / 4 = 14 units ( ) / 4 = 11 units

37 Scheduling in Batch Systems (2) Three level scheduling

38 Scheduling in Interactive Systems (1) Round Robin Scheduling –list of runnable processes –list of runnable processes after B uses up its quantum

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

40 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

41 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?

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

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