CSE 120 Principles of Operating Systems

Similar documents
Lecture 6 (cont.): Semaphores and Monitors

Lecture 7: CVs & Scheduling

CSE 120 Principles of Operating Systems Spring 2016

CSE 120 Principles of Operating Systems Spring 2016

CSE 120 Principles of Computer Operating Systems Fall Quarter, 2002 Halloween Midterm Exam. Instructor: Geoffrey M. Voelker

CSE 153 Design of Operating Systems

CSE 120 Principles of Operating Systems Spring 2016

Lecture 5: Synchronization w/locks

CS 318 Principles of Operating Systems

CS 318 Principles of Operating Systems

CS 162 Operating Systems and Systems Programming Professor: Anthony D. Joseph Spring Lecture 8: Semaphores, Monitors, & Condition Variables

CSE 120 Principles of Operating Systems

CSE 120. Fall Lecture 6: Semaphores. Keith Marzullo

CSE 120 Principles of Operating Systems

More Types of Synchronization 11/29/16

Synchronising Threads

CSE 120 Principles of Computer Operating Systems Fall Quarter, 2001 Midterm Exam. Instructor: Geoffrey M. Voelker

Condition Variables. Dongkun Shin, SKKU

More Synchronization; Concurrency in Java. CS 475, Spring 2018 Concurrent & Distributed Systems

CSE 120 Principles of Operating Systems

Concurrency and Synchronisation

CS 153 Design of Operating Systems Winter 2016

Lecture 9: Midterm Review

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

Performance Throughput Utilization of system resources

EECS 482 Introduction to Operating Systems

Synchronization. Dr. Yingwu Zhu

CS 31: Intro to Systems Misc. Threading. Kevin Webb Swarthmore College December 6, 2018

Condition Variables. Dongkun Shin, SKKU

CS 537 Lecture 8 Monitors. Thread Join with Semaphores. Dining Philosophers. Parent thread. Child thread. Michael Swift

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

The Synchronization Toolbox

Process Management And Synchronization

Operating Systems, Assignment 2 Threads and Synchronization

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

CSE 4/521 Introduction to Operating Systems

Concurrency and Synchronisation

Concurrency. Chapter 5

CSE 153 Design of Operating Systems

Background. The Critical-Section Problem Synchronisation Hardware Inefficient Spinning Semaphores Semaphore Examples Scheduling.

CSE 153 Design of Operating Systems Fall 2018

Synchronization. CS 475, Spring 2018 Concurrent & Distributed Systems

OPERATING SYSTEMS, ASSIGNMENT 2 KERNEL THREADS IN XV6, SYNCHRONIZATION

Condition Variables & Semaphores

Last Class: Synchronization

Page 1. Goals for Today" Atomic Read-Modify-Write instructions" Examples of Read-Modify-Write "

MS Windows Concurrency Mechanisms Prepared By SUFIAN MUSSQAA AL-MAJMAIE

Synchronization. CSCI 5103 Operating Systems. Semaphore Usage. Bounded-Buffer Problem With Semaphores. Monitors Other Approaches

CS370 Operating Systems

Lecture 4: Threads; weaving control flow

Lecture 8: September 30

CS 318 Principles of Operating Systems

Operating Systems CMPSCI 377 Spring Mark Corner University of Massachusetts Amherst

CS 471 Operating Systems. Yue Cheng. George Mason University Fall 2017

Operating Systems. Lecture 8

CS 153 Design of Operating Systems Winter 2016

Semaphores. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

[537] Semaphores. Tyler Harter

Semaphores and Monitors: High-level Synchronization Constructs

EI 338: Computer Systems Engineering (Operating Systems & Computer Architecture)

CPS 310 second midterm exam, 11/14/2014

Last Class: Synchronization. Review. Semaphores. Today: Semaphores. MLFQ CPU scheduler. What is test & set?

Solving the Producer Consumer Problem with PThreads

What's wrong with Semaphores?

Page 1. Goals for Today" Atomic Read-Modify-Write instructions" Examples of Read-Modify-Write "

Semaphores. To avoid busy waiting: when a process has to wait, it will be put in a blocked queue of processes waiting for the same event

Semaphores. Semaphores. Semaphore s operations. Semaphores: observations

Systèmes d Exploitation Avancés

Review: Processes. A process is an instance of a running program. POSIX Thread APIs:

Page 1. Goals for Today. Atomic Read-Modify-Write instructions. Examples of Read-Modify-Write

Concurrency: Deadlock and Starvation

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

W4118 Operating Systems. Instructor: Junfeng Yang

EEE3052: Introduction to Operating Systems. Fall Project #3

CSE 153 Design of Operating Systems

Operating Systems ECE344

OPERATING SYSTEMS - ASSIGNMENT 2 SYNCHRONIZATION & THREADS

EECS 482 Introduction to Operating Systems

Concurrency: Signaling and Condition Variables

Semaphores (by Dijkstra)

Concurrent Server Design Multiple- vs. Single-Thread

Concurrency, Thread. Dongkun Shin, SKKU

Background. Old Producer Process Code. Improving the Bounded Buffer. Old Consumer Process Code

Opera&ng Systems ECE344

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

Announcements. Class feedback for mid-course evaluations Receive about survey to fill out until this Friday

Chapter 5: Process Synchronization. Operating System Concepts 9 th Edition

CS 318 Principles of Operating Systems

Introduction to OS Synchronization MOS 2.3

Condition Synchronization

5 Classical IPC Problems

Synchronization Classic Problems

CS 333 Introduction to Operating Systems. Class 6 Monitors and Message Passing. Jonathan Walpole Computer Science Portland State University

CS450 OPERATING SYSTEMS FINAL EXAM ANSWER KEY

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

PROCESS SYNCHRONIZATION

Puzzle: Write synchronization code for oxygen and hydrogen molecules that enforces these constraints.

Page 1. CS162 Operating Systems and Systems Programming Lecture 8. Readers-Writers Language Support for Synchronization

Administrivia. Assignments 0 & 1 Class contact for the next two weeks Next week. Following week

Chap. 6 Part 1. CIS*3090 Fall Fall 2016 CIS*3090 Parallel Programming 1

Transcription:

CSE 120 Principles of Operating Systems Fall 2014 Project 1: Review Geoffrey M. Voelker

Locks & CVs Lock issues A thread cannot Acquire a lock it already holds A thread cannot Release a lock it does not hold A lock cannot be deleted if a thread is holding it Condition Variable issues A thread can only call Wait and Signal if it holds the mutex Wait must Release the mutex before the thread sleeps Wait must Acquire the mutex after the thread wakes up A condition variable cannot be deleted if a thread is waiting on it October 23, 2014 CSE 120 Project 1 -- Issues 2

Mailboxes Senders and receivers need to be synchronized Issues One sender and one receiver need to rendezvous Block all other senders while waiting for receiver in Send Block all other receivers while waiting for sender in Receive When a condition variable is signaled» The waiting thread is placed on the ready list» But it has not necessarily re-acquired the lock» It only reacquires the lock when it runs again» If another thread runs before it does, that thread can acquire the lock before the waiter does» Let s look at an example October 23, 2014 CSE 120 Project 1 -- Issues 3

Synchronizing with Wait/Signal while (1) { mutex->acquire(); printf( ping\n ); cond>signal(mutex); mutex->release(); } Signal places waiter on ready list, and then continues while (1) { mutex->acquire(); cond->wait(mutex); printf( pong\n ); mutex->release(); } BUT the waiter now competes with the signaler to re-acquire the mutex Output COULD be: ping ping ping October 23, 2014 CSE 120 Project 1 -- Issues 4

Interlocking with Wait/Signal Mutex *mutex; Condition *cond; void ping_pong () { mutex->acquire(); while (1) { printf( ping or pong\n ); cond->signal(mutex); cond->wait(mutex); } mutex->release(); } Waiting after signaling interlocks the two threads. The thread that signals then does a wait, and cannot proceed until the other thread wakes up from its wait and follows with a signal. October 23, 2014 CSE 120 Project 1 -- Issues 5

Thread::Join Issues A thread can only be Joined if specified during creation A thread can only be Joined after it has forked Only one thread can call Join on another A thread cannot call Join on itself A thread should be able to call Join on a thread that has already terminated» This is the tricky part» Should delay deleting thread object if it is to be joined If it is not going to be Joined, then don t change how it is deleted» Where is it deleted now? Look for use of threadtobedestroyed» Where should joined threads be deleted?» Need to delete synch primitives used by Join as well October 23, 2014 CSE 120 Project 1 -- Issues 6

Thread::setPriority(int) Issues Priorities have the entire range of an int» Both negative and positive If one thread has a priority value that is greater than another, that thread has a higher priority (simple integer comparisons) List implementation in list.cc has sorting capabilities Only adjust priority of thread when it is placed on ready list When transferring priority from a high thread to a low thread, the transfer is only temporary» When the low thread releases the lock, its priority reverts October 23, 2014 CSE 120 Project 1 -- Issues 7

Mating Whales Issues This is a synchronization problem like Bounded-Buffer, Readers/Writers, and Smoking Barber You do not need to implement anything inside of Nachos» But you will use the synchronization primitives you implemented» You can use any synch primitives you want You will implement Male, Female, and Matchmaker as functions in threadtest.cc (or equivalent), and create and fork threads to execute these functions in ThreadTest: T1->Fork(Male, 0); // could fork many males T2->Fork(Female, 0); // could fork many females T3->Fork(Matchmaker, 0); // could fork many matchmakers There is no API -- we will compile, run, and visually examine your code for correctness Comments will help (both you and us) October 23, 2014 CSE 120 Project 1 -- Issues 8

Tips Use DEBUG macro to trace the interaction of the synchronization primitives and thread context switches Run nachos d s d t to enable synch and thread debugs October 23, 2014 CSE 120 Project 1 -- Issues 9