1 COMP 3500 Introduction to Operating Systems Project 3 – Synchronization Overview Dr. Xiao Qin Auburn University

Slides:



Advertisements
Similar presentations
Operating Systems Semaphores II
Advertisements

Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee.
Ch 7 B.
Ch. 7 Process Synchronization (1/2) I Background F Producer - Consumer process :  Compiler, Assembler, Loader, · · · · · · F Bounded buffer.
Chapter 6: Process Synchronization
5.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Chapter 5: CPU Scheduling.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 6: Process Synchronization.
EEE 435 Principles of Operating Systems Interprocess Communication Pt II (Modern Operating Systems 2.3)
CY2003 Computer Systems Lecture 05 Semaphores - Theory.
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee.
Enforcing Mutual Exclusion, Semaphores. Four different approaches Hardware support Disable interrupts Special instructions Software-defined approaches.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 7: Process Synchronization Background The Critical-Section Problem Synchronization.
1 CS318 Project #3 Preemptive Kernel. 2 Continuing from Project 2 Project 2 involved: Context Switch Stack Manipulation Saving State Moving between threads,
5.6 Semaphores Semaphores –Software construct that can be used to enforce mutual exclusion –Contains a protected variable Can be accessed only via wait.
5.6.2 Thread Synchronization with Semaphores Semaphores can be used to notify other threads that events have occurred –Producer-consumer relationship Producer.
Semaphores CSCI 444/544 Operating Systems Fall 2008.
Race Conditions CS550 Operating Systems. Review So far, we have discussed Processes and Threads and talked about multithreading and MPI processes by example.
A. Frank - P. Weisberg Operating Systems Introduction to Cooperating Processes.
Adopted from and based on Textbook: Operating System Concepts – 8th Edition, by Silberschatz, Galvin and Gagne Updated and Modified by Dr. Abdullah Basuhail,
Semaphores Questions answered in this lecture: Why are semaphores necessary? How are semaphores used for mutual exclusion? How are semaphores used for.
CS4231 Parallel and Distributed Algorithms AY 2006/2007 Semester 2 Lecture 2 (19/01/2006) Instructor: Haifeng YU.
Introduction to Pthreads. Pthreads Pthreads is a POSIX standard for describing a thread model, it specifies the API and the semantics of the calls. Model.
Semaphores and Bounded Buffer Andy Wang Operating Systems COP 4610 / CGS 5765.
6.3 Peterson’s Solution The two processes share two variables: Int turn; Boolean flag[2] The variable turn indicates whose turn it is to enter the critical.
Operating Systems CMPSC 473 Mutual Exclusion Lecture 14: October 14, 2010 Instructor: Bhuvan Urgaonkar.
CS345 Operating Systems Threads Assignment 3. Process vs. Thread process: an address space with 1 or more threads executing within that address space,
Copyright ©: Nahrstedt, Angrave, Abdelzaher1 Semaphore and Mutex Operations.
Midterm 1 – Wednesday, June 4  Chapters 1-3: understand material as it relates to concepts covered  Chapter 4 - Processes: 4.1 Process Concept 4.2 Process.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Mutual Exclusion.
4061 Session 21 (4/3). Today Thread Synchronization –Condition Variables –Monitors –Read-Write Locks.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 7: Process Synchronization Background The Critical-Section Problem Synchronization.
Synchronizing Threads with Semaphores
1 Interprocess Communication (IPC) - Outline Problem: Race condition Solution: Mutual exclusion –Disabling interrupts; –Lock variables; –Strict alternation.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Synchronization.
Lab assignment 1: Synchronization
U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Synchronization Emery Berger and Mark Corner University.
CS 241 Section Week #7 (10/22/09). Topics This Section  Midterm Statistics  MP5 Forward  Classical Synchronization Problems  Problems.
1 Previous Lecture Overview  semaphores provide the first high-level synchronization abstraction that is possible to implement efficiently in OS. This.
Operating Systems COMP 4850/CISG 5550 Interprocess Communication, Part II Dr. James Money.
CSC 360 Instructor: Kui Wu More on Process Synchronization Semaphore, Monitor, Condition Variables.
6.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Module 6: Process Synchronization.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 22 Semaphores Classic.
Rensselaer Polytechnic Institute CSCI-4210 – Operating Systems David Goldschmidt, Ph.D.
pThread synchronization
6.1 Silberschatz, Galvin and Gagne ©2005 Operating System Principles 6.5 Semaphore Less complicated than the hardware-based solutions Semaphore S – integer.
Auburn University COMP 3500 Introduction to Operating Systems Project 3 – Synchronization Cats and Mice: Implementation.
Deadlock and Starvation
Auburn University COMP 3500 Introduction to Operating Systems Project 3 – Synchronization Cats and Mice Dr. Xiao Qin.
CPS110: Reader-writer locks
Process Synchronization: Semaphores
Auburn University COMP 3500 Introduction to Operating Systems Synchronization: Part 4 Classical Synchronization Problems.
PARALLEL PROGRAM CHALLENGES
Background on the need for Synchronization
Process Synchronization
Deadlock and Starvation
Auburn University COMP 3500 Introduction to Operating Systems Project 3 – Synchronization Condition Variables Dr. Xiao.
Chapter 5: Process Synchronization
CSE451 Basic Synchronization Spring 2001
Condition Variables and Producer/Consumer
Condition Variables and Producer/Consumer
Threading And Parallel Programming Constructs
Semaphore Originally called P() and V() wait (S) { while S <= 0
Process Synchronization
UNIVERSITY of WISCONSIN-MADISON Computer Sciences Department
Chapter 7: Synchronization Examples
Synchronization Primitives – Semaphore and Mutex
Chapter 6 Synchronization Principles
CSE 153 Design of Operating Systems Winter 2019
Lecture 20: Synchronization
Presentation transcript:

1 COMP 3500 Introduction to Operating Systems Project 3 – Synchronization Overview Dr. Xiao Qin Auburn University

Project Objectives To implement the lock mechanism To implement condition variables To solve a synchronization problem using different mechanisms To improve your source code reading skills To strengthen your debugging skill Two weeks to achieve the above objectives!

Three Tasks Task 1: Code-Reading Assignment (15%) Individual; Soft Deadline: 9/12 Task 2: Programming Assignment (70%) Collaboration; Soft Deadline: 9/19 Task 3: Written Assignment (15%) Discussion; Soft Deadline: 9/21

Task 1: Code-Reading Assignment Time Allocation: < 2 hours Five Thread Questions (30-40 min) Three Scheduler Questions (30-40 min) Two Synchronization Questions (<1 hour) Use the grep command: %grep -r “hardclock”.

Task 2: Programming Assignment Subtask 1: Implementing Locks: 15% Subtask 2: Implementing Condition Variables (cv): 15% Subtask 3: A semaphore-based solution in catsem.c: 15% Subtask 4: A “CV + locks” based solution in catlock.c: 15%

Task 3: Written Assignment You will have to offer two solutions to the Synchronization Problem: Cats and Mice (1) Explain how each of your solutions avoid starvation. (2) Can you derive any principles about the use of these different synchronization primitives (semaphores vs. Condition Variables)?

Tip 1: the kmalloc and kfree functions int* int_ptr; int_ptr = kmalloc(sizeof(int)); kfree(int_ptr);

Tip 2: How to turn interrupts off? int spl = splhigh(); /* * Here is a section that must be * atomically executed */... splx(spl);

Semaphore in OS/161 What is the difference? What we have learned: typedef struct { int value; struct process *L; } semaphore; The semaphore in OS/161: struct semaphore { char *name; volatile int count; };

Implement P() using Semaphore in OS/161

Implement V() using Semaphore in OS/161

How to P() and V() collaborate through thread_sleep() and thread_wakeup()? See also Question (9) in Section 4.3

Locks and Condition Variables (CV) in OS/161 No monitor in OS161 We will use condition variables We make condition variables independent (i.e., not associated with a monitor) We will associate CV with a lock (mutex) –Threads must first acquire the lock (mutex) –CV::Wait releases the lock before blocking, acquires it after waking up

Review 1: Semaphore

Review 2: Lock

POSIX Mutex-related Functions int pthread_mutex_init(pthread_mutex_t *restrict mutex, const pthread_mutexattr_t *restrict attr); int pthread_mutex_destroy(pthread_mutex_t *mutex); int pthread_mutex_lock(pthread_mutex_t *mutex); int pthread_mutex_trylock(pthread_mutex_t *mutex); int pthread_mutex_unlock(pthread_mutex_t *mutex);

Condition Variable or CV

Semaphore vs. Condition Variable

Producer/Consumer Problem General Statement: one or more producers are generating data and placing these in a buffer a single consumer is taking items out of the buffer one at a time only one producer or consumer may access the buffer at any one time The Problem: ensure that the producer can’t add data into full buffer and consumer can’t remove data from an empty buffer

Figure 5.9 An Incorrect Solution to the Infinite-Buffer Producer/Consu mer Problem Using Binary Semaphores