Uniprocessor Lock Implementation

Slides:



Advertisements
Similar presentations
LINKED LIST, STACKS AND QUEUES Saras M Srivastava, PGT – Comp. Sc. Kendriya Vidyalaya TengaValley.
Advertisements

For(int i = 1; i
Introduction to Computer Science Robert Sedgewick and Kevin Wayne Recursive Factorial Demo pubic class Factorial {
Data Structure Lecture-5
1 Lab 4 Westfield High School APCS LAB 4 Parameters, apvectors, structs.
1 Data Structures - CSCI 102 CS102 C++ Operator Overloading Prof Tejada.
LCS Non-Dynamic Version int function lcs (x, y, i, j) begin if (i = 0) or (j = 0) return 0; else if (x[i] = y[j]) return lcs(x, y, i-1, j-1)+1; else return.
SORTING AND ASYMPTOTIC COMPLEXITY Lecture 12 CS2110 – Spring 2014 File searchSortAlgorithms.zip on course website (lecture notes for lectures 12, 13) contains.
1 Data Structures CSCI 132, Spring 2014 Lecture 15 Recursion.
Homework 6 Sarah Diesburg Operating Systems CS 3430.
U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Emery Berger University of Massachusetts Amherst Operating Systems CMPSCI 377 Lecture.
09/30/04 Assignment 2 Non-preemptive scheduling COS Operating System Fall 2004.
Synchronization (other solutions …). Announcements Assignment 2 is graded Project 1 is due today.
CS 140 Lecture Notes: Lock ImplementationSlide 1 Uniprocessor Locks, v1 void lock_acquire(struct lock *l) { while (1) { Disable interrupts; if (!l->locked)
U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Emery Berger University of Massachusetts, Amherst Operating Systems CMPSCI 377 Lecture.
Queues CS-240 & CS-341 Dick Steflik. Queues First In, First Out operation – FIFO As items are added they are chronologically ordered, items are removed.
CS 140 Lecture Notes: Lock ImplementationSlide 1 Uniprocessor Locks void lock_acquire(struct lock *l) { intr_disable(); if (!l->locked) { l->locked = 1;
Multithreaded Web Server.
Intro to Scheduling (+ OS sync wrap) David E. Culler CS162 – Operating Systems and Systems Programming Lecture 10 Sept 17, 2014 Reading: A&D HW 2.
U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Emery Berger University of Massachusetts, Amherst Operating Systems CMPSCI 377 Lecture.
COMP 111 Threads and concurrency Sept 28, Tufts University Computer Science2 Who is this guy? I am not Prof. Couch Obvious? Sam Guyer New assistant.
CS 4284 Systems Capstone Godmar Back Concurrency & Synchronization.
CS 3204 Operating Systems Godmar Back Lecture 7. 12/12/2015CS 3204 Fall Announcements Project 1 due on Sep 29, 11:59pm Reading: –Read carefully.
CSCI-375 Operating Systems Lecture Note: Many slides and/or pictures in the following are adapted from: slides ©2005 Silberschatz, Galvin, and Gagne Some.
1 Synchronization Threads communicate to ensure consistency If not: race condition (non-deterministic result) Accomplished by synchronization operations.
COSC 3407: Operating Systems Lecture 9: Readers-Writers and Language Support for Synchronization.
CPS110: Thread cooperation Landon Cox. Constraining concurrency  Synchronization  Controlling thread interleavings  Some events are independent  No.
1 Previous Lecture Overview  semaphores provide the first high-level synchronization abstraction that is possible to implement efficiently in OS. This.
Print Row Function void PrintRow(float x[ ][4],int i) { int j; for(j=0;j
Implementing Lock. From the Previous Lecture  The “too much milk” example shows that writing concurrent programs directly with load and store instructions.
Int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } 5 void main () { Int Sum; : Sum = fact (5); : } Factorial Program Using Recursion.
3/17/2016cse synchronization-p2 © Perkins, DW Johnson and University of Washington1 Synchronization Part 2 CSE 410, Spring 2008 Computer.
Implementing Mutual Exclusion Andy Wang Operating Systems COP 4610 / CGS 5765.
CS162 Section 2. True/False A thread needs to own a semaphore, meaning the thread has called semaphore.P(), before it can call semaphore.V() False: Any.
Operating Systems NWEN 301 Lecture 6 More Concurrency.
29 June 2015 Charles Reiss CS162: Operating Systems and Systems Programming Lecture 5: Basic Scheduling + Synchronization.
CS703 - Advanced Operating Systems
CS703 – Advanced Operating Systems
Atomic Operations in Hardware
Atomic Operations in Hardware
Queues Asynchronous data transfer between tasks
Monitors, Condition Variables, and Readers-Writers
Introduction to Operating Systems
CSC215 Homework Homework 11 Due date: Dec 19, 2016.
CS 140 Lecture Notes: Lock Implementation
Linked Lists: Implementation of Queue & Deque
Too Much Milk With Locks
Too Much Milk With Locks
Too Much Milk With Locks
CS 140 Lecture Notes: Protection
Too Much Milk With Locks
Too Much Milk With Locks
CS703 - Advanced Operating Systems
UNIVERSITY of WISCONSIN-MADISON Computer Sciences Department
Queues FIFO Enqueue Dequeue Peek.
CSE 451 Autumn 2003 Section 3 October 16.
Implementing Mutual Exclusion
CS 140 Lecture Notes: Introduction
Implementing Mutual Exclusion
September 12, 2012 Ion Stoica CS162 Operating Systems and Systems Programming Lecture 5 Semaphores, Conditional Variables.
Chapter 6: Synchronization Tools
Homework 4.
CS148 Introduction to Programming II
CSE 153 Design of Operating Systems Winter 19
CS 140 Lecture Notes: Protection
CS 140 Lecture Notes: Introduction
Too Much Milk With Locks
CSCE 206 Lab Structured Programming in C
Don Porter Portions courtesy Emmett Witchel
Single-Core Lock Implementation
Presentation transcript:

Uniprocessor Lock Implementation struct lock { int locked; struct queue q; }; void lock_acquire( struct lock *l) { intr_disable(); if (!l->locked) { l->locked = 1; } else { queue_add(&l->q, thread_current()); thread_block(); } intr_enable(); void lock_release( struct lock *l) { intr_disable(); if (queue_empty(&l->q) { l->locked = 0; } else { thread_unblock( queue_remove(&l->q)); } intr_enable(); CS 140 Lecture Notes: Lock Implementation

CS 140 Lecture Notes: Lock Implementation Locks for Multi-Core, v1 struct lock { int locked; }; void lock_acquire( struct lock *l) { while (swap(&l->locked, 1)) { /* Do nothing */ } void lock_release( struct lock *l) { l->locked = 0; } CS 140 Lecture Notes: Lock Implementation

CS 140 Lecture Notes: Lock Implementation Locks for Multi-Core, v2 struct lock { int locked; struct queue q; }; void lock_acquire( struct lock *l) { if (swap(&l->locked, 1)) { queue_add(&l->q, thread_current()); thread_block(); } void lock_release( struct lock *l) { if (queue_empty(&l->q) { l->locked = 0; } else { thread_unblock( queue_remove(&l->q)); } CS 140 Lecture Notes: Lock Implementation

CS 140 Lecture Notes: Lock Implementation Locks for Multi-Core, v3 struct lock { int locked; struct queue q; int sync; }; void lock_acquire( struct lock *l) { while (swap(&l->sync, 1)) { /* Do nothing */ } if (!l->locked) { l->locked = 1; l->sync = 0; } else { queue_add(&l->q, thread_current()); thread_block(); void lock_release( struct lock *l) { while (swap(&l->sync, 1)) { /* Do nothing */ } if (queue_empty(&l->q) { l->locked = 0; } else { thread_unblock( queue_remove(&l->q)); l->sync = 0; CS 140 Lecture Notes: Lock Implementation

CS 140 Lecture Notes: Lock Implementation Locks for Multi-Core, v4 struct lock { int locked; struct queue q; int sync; }; void lock_acquire( struct lock *l) { while (swap(&l->sync, 1)) { /* Do nothing */ } if (!l->locked) { l->locked = 1; l->sync = 0; } else { queue_add(&l->q, thread_current()); thread_block(&l->sync); void lock_release( struct lock *l) { while (swap(&l->sync, 1)) { /* Do nothing */ } if (queue_empty(&l->q) { l->locked = 0; } else { thread_unblock( queue_remove(&l->q)); l->sync = 0; CS 140 Lecture Notes: Lock Implementation

CS 140 Lecture Notes: Lock Implementation Locks for Multi-Core, v5 struct lock { int locked; struct queue q; int sync; }; void lock_acquire( struct lock *l) { intr_disable(); while (swap(&l->sync, 1)) { /* Do nothing */ } if (!l->locked) { l->locked = 1; l->sync = 0; } else { queue_add(&l->q, thread_current()); thread_block(&l->sync); intr_enable(); void lock_release( struct lock *l) { intr_disable(); while (swap(&l->sync, 1)) { /* Do nothing */ } if (queue_empty(&l->q) { l->locked = 0; } else { thread_unblock( queue_remove(&l->q)); l->sync = 0; intr_enable(); CS 140 Lecture Notes: Lock Implementation