Threads, Synchronization, and Scheduling. Eric Wu

Similar documents
CSE 451: Operating Systems Winter Lecture 7 Synchronization. Steve Gribble. Synchronization. Threads cooperate in multithreaded programs

Synchronization I. Jo, Heeseung

CSE 451: Operating Systems Winter Lecture 7 Synchronization. Hank Levy 412 Sieg Hall

CSE 153 Design of Operating Systems

Synchronization I. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University


Lecture 5: Synchronization w/locks

More on Synchronization and Deadlock

10/17/ Gribble, Lazowska, Levy, Zahorjan 2. 10/17/ Gribble, Lazowska, Levy, Zahorjan 4

Lecture 9: Midterm Review

Last Class: Monitors. Real-world Examples

Real-Time Programming

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

Last Class: Synchronization Problems. Need to hold multiple resources to perform task. CS377: Operating Systems. Real-world Examples

Last Class: Deadlocks. Today

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

Threads Implementation. Jo, Heeseung

EECS 482 Introduction to Operating Systems

CS 4410 Operating Systems. Review 1. Summer 2016 Cornell University

EECS 482 Introduction to Operating Systems

Operating Systems. Synchronization

High Performance Computing Course Notes Shared Memory Parallel Programming

Last Class: Synchronization

CSE 4/521 Introduction to Operating Systems

Synchronization. CS61, Lecture 18. Prof. Stephen Chong November 3, 2011

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

Concurrency Issues. Past lectures: What about coordinated access across multiple objects? Today s lecture:

CSC 4320 Test 1 Spring 2017

Threads Questions Important Questions

Multi-threading in Java. Jeff HUANG

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING UNIT I

POSIX Threads: a first step toward parallel programming. George Bosilca

Taming Dava Threads. Apress ALLEN HOLUB. HLuHB Darmstadt

8: Scheduling. Scheduling. Mark Handley

CMSC421: Principles of Operating Systems

Today: Synchronization. Recap: Synchronization

Lecture 8: September 30

Interrupts, Etc. Operating Systems In Depth V 1 Copyright 2018 Thomas W. Doeppner. All rights reserved.

Concurrent & Distributed Systems Supervision Exercises

RTOS Real T i Time me Operating System System Concepts Part 2

Vulkan Timeline Semaphores

Vulkan: Scaling to Multiple Threads. Kevin sun Lead Developer Support Engineer, APAC PowerVR Graphics

CSE 153 Design of Operating Systems Fall 2018

Last Class: CPU Scheduling! Adjusting Priorities in MLFQ!

Parallelism and Concurrency. Motivation, Challenges, Impact on Software Development CSE 110 Winter 2016

Concurrency: Deadlock and Starvation

Concurrency: State Models & Design Patterns

CS 318 Principles of Operating Systems

Chendu College of Engineering & Technology

Multiprocessor Systems. Chapter 8, 8.1

UNIT:2. Process Management

I/O Systems. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Lecture notes Lectures 1 through 5 (up through lecture 5 slide 63) Book Chapters 1-4

Locks. Dongkun Shin, SKKU

Problem Set 2. CS347: Operating Systems

CS 153 Design of Operating Systems Winter 2016

CHAPTER 6: PROCESS SYNCHRONIZATION

INDIAN INSTITUTE OF TECHNOLOGY GUWAHATI

C09: Process Synchronization

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

Synchronization I q Race condition, critical regions q Locks and concurrent data structures q Next time: Condition variables, semaphores and monitors

Concurrency: Deadlock and Starvation. Chapter 6

Preemptive Scheduling and Mutual Exclusion with Hardware Support

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

Introduction to Real-Time Operating Systems

Synchronization Spinlocks - Semaphores

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

Utilizing Linux Kernel Components in K42 K42 Team modified October 2001


Chapter 6 Process Synchronization

CSE 410 Final Exam 6/09/09. Suppose we have a memory and a direct-mapped cache with the following characteristics.

CSE 153 Design of Operating Systems

Synchronization COMPSCI 386

PROCESSES AND THREADS THREADING MODELS. CS124 Operating Systems Winter , Lecture 8

Process Management And Synchronization

Operating Systems Antonio Vivace revision 4 Licensed under GPLv3

CS 31: Introduction to Computer Systems : Threads & Synchronization April 16-18, 2019

Administrivia. p. 1/20

I/O Systems. Jo, Heeseung

1. Draw and explain program flow of control without and with interrupts. [16]

Chapter 6: Process Synchronization. Operating System Concepts 9 th Edit9on

Chapter 7: Deadlocks. Operating System Concepts 9 th Edition

EECS 482 Introduction to Operating Systems

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

Threading and Synchronization. Fahd Albinali

Concurrency Race Conditions and Deadlocks

CPS 310 second midterm exam, 11/14/2014

CS140 Operating Systems and Systems Programming Midterm Exam

CSE 4/521 Introduction to Operating Systems. Lecture 29 Windows 7 (History, Design Principles, System Components, Programmer Interface) Summer 2018

Multitasking / Multithreading system Supports multiple tasks

Introduction to I/O. 1-Slide Overview to File Management

Concurrency Control. Synchronization. Brief Preview of Scheduling. Motivating Example. Motivating Example (Cont d) Interleaved Schedules

CSC501 Operating Systems Principles. Process Synchronization

CS370 Operating Systems

CPS 110 Midterm. Spring 2011

Multiprocessor System. Multiprocessor Systems. Bus Based UMA. Types of Multiprocessors (MPs) Cache Consistency. Bus Based UMA. Chapter 8, 8.

SYED AMMAL ENGINEERING COLLEGE CS6401- OPERATING SYSTEM

Deadlock. Concurrency: Deadlock and Starvation. Reusable Resources

Lesson 6: Process Synchronization

Process Coordination and Shared Data

Transcription:

Threads, Synchronization, and Scheduling Eric Wu (ericwu@cs)

Topics for Today Project 2 Due tomorrow! Project 3 Due Feb. 17 th! Threads Synchronization Scheduling

Project 2 Troubleshooting: Stock kernel doesn t run on the VM Solution: do not hit reset! Use graceful shutdown. Variable scoping issues! Solution: only declare global functions or variables once. All other instances of variables should be extern. Other questions?

Project 3 Implement a file-copy utility This is done entirely in user space. (or ) Three parts Multithreaded + synchronous I/O Single threaded + asynchronous I/O Performance analysis of these two implementations

Synchronous I/O in Windows User Code ReadFile(&buf); Kernel Code NtReadFile() { Submit request Wait for signal } Asynchronous User Code ev = CreateEvent() ReadFile(&buf, ev); // do whatever WaitForSingleObject(ev) Kernel Code NtReadFile() { Submit request } Kernel Code NtWaitForSingleObject() { Wait for signal }

I/O in Windows Advantages of sync I/O? Advantages of async I/O?

I/O in Windows Advantages of sync I/O? Easier to program Advantages of async I/O? Potentially more efficient Can also make sync I/O more efficient with threading! How?

Project 3 Multithreaded + Sync I/O ReadFile() ReadFile() WriteFile() WriteFile() Buffer Buffer Thread 1 Thread 2

Project 3 Single Threaded + Async I/O ReadFile() ReadFile() WriteFile() WriteFile() Buffer Buffer Thread 1 WaitForMultipleObjects([ev1, ev2])

Threads Quick concept checks: What resources in memory are shared among threads? In what scenario(s) does multi-threading not perform better than single-threading?

Amdahl s Law (Abridged) Overall performance is given by a weighted proportion of performance increases across all segments of code. N i = percent segment of the program P i = performance change of that segment.

Amdahl s Law (Abridged) 30% 2x performance 40% unaffected 30% 2x performance

Amdahl s Law (Abridged) 30% 2x performance 40% unaffected 30% 2x performance

Why do we need it? Synchronization

Synchronization Why do we need it? Make data handling safe! This was the focus of project 2

Synchronization Mutexes and Locks Semaphores Condition Variables Monitors (won t cover in this section!)

Mutexes and Locks Implemented in two ways below: Spinlocks Busy wait (while ( ) { continue; }) until lock is released. Advantages and disadvantages? Blocking/queueing mutexes: Waiting threads Mutex T1 T3 T4 held = TRUE activethread = T2 Executing thread

Semaphores Similar to locks/mutexes, but can have more than one resource. Operations: wait (Execute thread if enough resources, else put on waiting queue.) signal (Return a resource if no waiting threads, else execute a thread from waiting queue. Caller of signal also executes.)

Semaphores Similar to locks/mutexes, but can have more than one resource. Operations: wait (acquire a resource) signal (release a resource)

Semaphores Waiting threads T1 T3 T4 Semaphore Free resources: 2 T2 T5 T6 Executing threads

Semaphores Benefits over mutexes and locks? Weaknesses?

Semaphores Benefits over mutexes and locks? Better resource allocation! Weaknesses? Easier to mess up Forget to acquire Forget to release Even more difficult with non one-to-one resource to acquirer mappings

Scheduling Two important decisions: When do I reschedule the CPU? Who gets the CPU after I reschedule it?

When do I reschedule the CPU? Cooperative scheduling Reschedule when: A thread blocks on I/O A thread yields() A thread terminates Problems? Preemptive scheduling Reschedules at any time Problems?

Who gets the CPU? Many algorithms for scheduling What are some factors to consider in scheduling?

Who gets the CPU? Many algorithms for scheduling What are some factors to consider in scheduling? Not limited to: priority, waiting time, CPU utilization, average execution time, See lecture slides!