CS 153 Design of Operating Systems Spring 18

Size: px
Start display at page:

Download "CS 153 Design of Operating Systems Spring 18"

Transcription

1 CS 153 Design of Operating Systems Spring 18 Lectre 11: Semaphores Instrctor: Chengy Song Slide contribtions from Nael Ab-Ghazaleh, Harsha Madhyvasta and Zhiyn Qian

2 Last time Worked throgh software implementation of locks Good concrrency practice Ended p with Dekker and Peterson s algorithms» Work nder assmptions of atomic and in order memory system So, they do not work in practice Compiler reorders And memory system is not ordered Introdced hardware spport for synchronization Two flavors:» Atomic instrctions that read and pdate a variable E.g., test-and-set, xchange,» Disable interrpts CS 153 Lectre 11 Semaphores 2

3 Dekker s Algorithm Bool flag[2]l Int trn = 1; flag[0] = 1; while (flag[1]!= 0) { //while if(trn == 2) { flag[0] = 0; while (trn == 2); flag[0] = 1; //if critical section flag[0]=0; trn=2; otside of critical section flag[1] = 1; while (flag[0]!= 0) { //while if(trn == 1) { flag[1] = 0; while (trn == 1); flag[1] = 1; //if critical section flag[1]=0; trn=1; otside of critical section CS 153 Lectre 11 Semaphores 3

4 Peterson's Algorithm int trn = 1; bool try1 = false, try2 = false; while (tre) { try1 = tre; trn = 2; while (try2 && trn!= 1) ; critical section try1 = false; otside of critical section while (tre) { try2 = tre; trn = 1; while (try1 && trn!= 2) ; critical section try2 = false; otside of critical section This satisfies all the reqirements Here's why... CS 153 Lectre 11 Semaphores 4

5 Peterson's Algorithm: analysis int trn = 1; bool try1 = false, try2 = false; while (tre) { { try1 (trn == 1 trn == 2) 1 try1 = tre; { try1 (trn == 1 trn == 2) 2 trn = 2; { try1 (trn == 1 trn == 2) 3 while (try2 && trn!= 1) ; { try1 (trn == 1 try2 (try2 (yellow at 6 or at 7)) critical section 4 try1 = false; { try1 (trn == 1 trn == 2) otside of critical section while (tre) { { try2 (trn == 1 trn == 2) 5 try2 = tre; { try2 (trn == 1 trn == 2) 6 trn = 1; { try2 (trn == 1 trn == 2) 7 while (try1 && trn!= 2) ; { try2 (trn == 2 try1 (try1 (ble at 2 or at 3)) critical section 8 try2 = false; { try2 (trn == 1 trn == 2) otside of critical section (ble at 4) try1 (trn == 1 try2 (try2 (yellow at 6 or at 7)) (yellow at 8) try2 (trn == 2 try1 (try1 (ble at 2 or at 3))... (trn == 1 trn == 2) CS 153 Lectre 11 Semaphores 5

6 Using Test-And-Set Here is or lock implementation with test-and-set: strct lock { int held = 0; void acqire (lock) { while (test-and-set(&lock->held)); void release (lock) { lock->held = 0; When will the while retrn? What is the vale of held? Does it satisfy critical region reqirements? (mtex, progress, bonded wait, performance?) CS 153 Lectre 11 Semaphores 6

7 Disabling Interrpts Another implementation of acqire/release is to disable interrpts: strct lock { void acqire (lock) { disable interrpts; void release (lock) { enable interrpts; Note that there is no state associated with the lock Can two threads disable interrpts simltaneosly? CS 153 Lectre 11 Semaphores 7

8 On Disabling Interrpts Disabling interrpts blocks notification of external events that cold trigger a context switch (e.g., timer) In a real system, this is only available to the kernel Why? Disabling interrpts is insfficient on a mltiprocessor Back to atomic instrctions Like spinlocks, only want to disable interrpts to implement higher-level synchronization primitives Don t want interrpts disabled between acqire and release CS 153 Lectre 11 Semaphores 8

9 Smmarize Where We Are Goal: Use mtal exclsion to protect critical sections of code that access shared resorces Method: Use locks (spinlocks or disable interrpts) Problem: Critical sections can be long Spinlocks: Threads waiting to acqire lock spin in test-and-set loop Wastes CPU cycles Longer the CS, the longer the spin Greater the chance for lock holder to be interrpted Memory consistency model cases problems (ot of scope of this class) acqire(lock) Critical section release(lock) Disabling Interrpts: Shold not disable interrpts for long periods of time Can miss or delay important events (e.g., timer, I/O) CS 153 Lectre 11 Semaphores 9

10 Implementing Locks Block waiters, interrpts enabled in critical sections strct lock { int held = 0; qee Q; void acqire (lock) { Disable interrpts; if (lock->held) { pt crrent thread on lock Q; block crrent thread; lock->held = 1; Enable interrpts; void release (lock) { Disable interrpts; if (Q) remove and nblock a waiting thread; else lock->held = 0; Enable interrpts; acqire(lock) Interrpts Disabled Critical section Interrpts Enabled release(lock) Interrpts Disabled CS 153 Lectre 11 Semaphores 10

11 Higher-Level Synchronization Locks so far inefficient when critical sections are long Spinlocks inefficient Disabling interrpts can miss or delay important events Instead, we want synchronization mechanisms that Plan: Block waiters Leave interrpts enabled inside the critical section Look at two common high-level mechanisms» Semaphores: binary (mtex) and conting» Monitors: mtexes and condition variables Use them to solve common synchronization problems CS 153 Lectre 11 Semaphores 11

12 Semaphores Semaphores are an abstract data type that provide mtal exclsion to critical sections Block waiters, interrpts enabled within critical section Described by Dijkstra in THE system in 1968 Semaphores are integers that spport two operations: wait(semaphore): decrement, block ntil semaphore is open» Also P(), after the Dtch word for test, or down() signal(semaphore): increment, allow another thread to enter» Also V() after the Dtch word for increment, or p() That's it! No other operations not even jst reading its vale Semaphore safety property: the semaphore vale is always greater than or eqal to 0 CS 153 Lectre 11 Semaphores 12

13 Blocking in Semaphores Associated with each semaphore is a qee of waiting threads/processes When wait() is called by a thread: If semaphore is open, thread contines If semaphore is closed, thread blocks on qee Then signal() opens the semaphore: If a thread is waiting on the qee, the thread is nblocked If no threads are waiting on the qee, the signal is remembered for the next thread CS 153 Lectre 11 Semaphores 13

14 Semaphore Types Semaphores come in two types Mtex semaphore (or binary semaphore) Represents single access to a resorce Garantees mtal exclsion to a critical section Conting semaphore (or general semaphore) Mltiple threads pass the semaphore determined by cont» mtex has cont = 1, conting has cont = N Represents a resorce with many nits available or a resorce allowing some nsynchronized concrrent access (e.g., reading) CS 153 Lectre 11 Semaphores 14

15 Using Semaphores Use is similar to or locks, bt semantics are different strct Semaphore { int vale; Qee q; S; withdraw (accont, amont) { wait(s); balance = get_balance(accont); balance = balance amont; pt_balance(accont, balance); signal(s); retrn balance; Threads block critical section wait(s); balance = get_balance(accont); balance = balance amont; wait(s); wait(s); pt_balance(accont, balance); signal(s); signal(s); It is ndefined which thread rns after a signal signal(s); CS 153 Lectre 11 Semaphores 15

16 Beyond Mtal Exclsion We ve looked at a simple example for sing synchronization Mtal exclsion while accessing a bank accont We re going to se semaphores to look at more interesting examples Conting critical region Ordering threads Readers/Writers Prodcer consmer with bonded bffers More general examples CS 153 Lectre 11 Semaphores 16

17 Example Problem(s) Create a critical region where p to three threads (bt no more) may enter at a time Exploits the conting featre of semaphores Order operations across two threads; thread A exectes first, then thread B exectes Exploits the ability to initialize semaphores to different vales CS 153 Lectre 11 Semaphores 17

18 Readers/Writers Problem Readers/Writers Problem: An object is shared among several threads Some threads only read the object, others only write it We can allow mltiple readers bt only one writer» Let #r be the nmber of readers, #w be the nmber of writers» Safety: (#r 0) (0 #w 1) ((#r > 0) (#w = 0)) Use three variables int readcont nmber of threads reading object Semaphore mtex control access to readcont Semaphore w_or_r exclsive writing or reading CS 153 Lectre 11 Semaphores 18

19 Readers/Writers // nmber of readers int readcont = 0; // mtal exclsion to readcont Semaphore mtex = 1; // exclsive writer or reader Semaphore w_or_r = 1; writer { wait(w_or_r); // lock ot readers Write; signal(w_or_r); // p for grabs reader { wait(mtex); // lock readcont readcont += 1; // one more reader if (readcont == 1) wait(w_or_r); // synch w/ writers signal(mtex); // nlock readcont Read; wait(mtex); // lock readcont readcont -= 1; // one less reader if (readcont == 0) signal(w_or_r); // p for grabs signal(mtex); // nlock readcont CS 153 Lectre 11 Semaphores 19

20 Readers/Writers Notes w_or_r provides mtex between readers and writers Readers wait/signal when readcont goes from 0 to 1 or 1 to 0 If a writer is writing, where will readers be waiting? Once a writer exits, all readers can fall throgh Which reader gets to go first? Is it garanteed that all readers will fall throgh? If readers and writers are waiting, and a writer exits, who goes first? Why do readers se mtex? What if the signal is above if (readcont == 1)? If read in progress when writer arrives, when can writer get access? CS 153 Lectre 11 Semaphores 20

21 Bonded Bffer Problem: Set of bffers shared by prodcer and consmer threads Prodcer inserts jobs into the bffer set Consmer removes jobs from the bffer set Prodcer and consmer execte at different rates No serialization of one behind the other Tasks are independent (easier to think abot) The bffer set allows each to rn withot explicit handoff Data strctre shold not be corrpted De to race conditions Or prodcer writing when fll Or consmer deleting when empty CS 153 Lectre 11 Semaphores 21

22 Bonded Bffer (2) Semaphore mtex = 1; // mtal exclsion to shared set of bffers Semaphore empty = N; // cont of empty bffers (all empty to start) Semaphore fll = 0; // cont of fll bffers (none fll to start) prodcer { while (1) { Prodce new resorce; wait(empty); // wait for empty bffer wait(mtex); // lock bffer list Add resorce to an empty bffer; signal(mtex); // nlock bffer list signal(fll); // note a fll bffer consmer { while (1) { wait(fll); // wait for a fll bffer wait(mtex); // lock bffer list Remove resorce from a fll bffer; signal(mtex); // nlock bffer list signal(empty); // note an empty bffer Consme resorce; CS 153 Lectre 11 Semaphores 23

23 Bonded Bffer (3) Why need the mtex at all? The pattern of signal/wait on fll/empty is a common constrct often called an interlock Prodcer-Consmer and Bonded Bffer are classic examples of synchronization problems We will see and practice others CS 153 Lectre 11 Semaphores 24

24 Semaphore Smmary Semaphores can be sed to solve any of the traditional synchronization problems However, they have some drawbacks They are essentially shared global variables» Can potentially be accessed anywhere in program No connection between the semaphore and the data being controlled by the semaphore Used both for critical sections (mtal exclsion) and coordination (schedling)» Note that I had to se comments in the code to distingish No control or garantee of proper sage Sometimes hard to se and prone to bgs Another approach: Use programming langage spport CS 153 Lectre 11 Semaphores 25

CS 153 Design of Operating Systems Spring 18

CS 153 Design of Operating Systems Spring 18 CS 153 Design of Operating Systems Spring 18 Lectre 10: Lock Implementation Instrctor: Chengy Song Slide contribtions from Nael Ab-Ghazaleh, Harsha Madhyvasta and Zhiyn Qian Recap: Synchronization Race

More information

CS 153 Design of Operating Systems Spring 18

CS 153 Design of Operating Systems Spring 18 CS 153 Design of Operating Systems Spring 18 Lectre 9: Synchronization (1) Instrctor: Chengy Song Slide contribtions from Nael Ab-Ghazaleh, Harsha Madhyvasta and Zhiyn Qian Cooperation between Threads

More information

CS 153 Design of Operating Systems Spring 18

CS 153 Design of Operating Systems Spring 18 CS 153 Design of Operating Systems Spring 18 Midterm Review Midterm in class on Friday (May 4) Covers material from arch spport to deadlock Based pon lectre material and modles of the book indicated on

More information

CS 153 Design of Operating Systems Spring 18

CS 153 Design of Operating Systems Spring 18 CS 153 Design of Operating Systems Spring 18 Lectre 12: Deadlock Instrctor: Chengy Song Slide contribtions from Nael Ab-Ghazaleh, Harsha Madhyvasta and Zhiyn Qian Deadlock the deadly embrace! Synchronization

More information

CS 153 Design of Operating Systems Spring 18

CS 153 Design of Operating Systems Spring 18 CS 153 Design of Operating Systems Spring 18 Lectre 8: Threads Instrctor: Chengy Song Slide contribtions from Nael Ab-Ghazaleh, Harsha Madhyvasta and Zhiyn Qian Processes P1 P2 Recall that Bt OS A process

More information

CSE 120. Fall Lecture 6: Semaphores. Keith Marzullo

CSE 120. Fall Lecture 6: Semaphores. Keith Marzullo CSE 120 Principles of Operating Systems Fall 2007 Lecture 6: Semaphores Keith Marzullo Announcements Homework #2 out Homework #1 almost graded... Discussion session on Wednesday will entertain questions

More information

CS 153 Design of Operating Systems Spring 18

CS 153 Design of Operating Systems Spring 18 CS 153 Design of Operating Systems Spring 18 Lectre 15: Virtal Address Space Instrctor: Chengy Song Slide contribtions from Nael Ab-Ghazaleh, Harsha Madhyvasta and Zhiyn Qian OS Abstractions Applications

More information

CS 153 Design of Operating Systems Winter 2016

CS 153 Design of Operating Systems Winter 2016 CS 153 Design of Operating Systems Winter 2016 Lecture 9: Semaphores and Monitors Some slides from Matt Welsh Summarize Where We Are Goal: Use mutual exclusion to protect critical sections of code that

More information

CS 153 Design of Operating Systems

CS 153 Design of Operating Systems CS 153 Design of Operating Systems Spring 18 Lectre 3: OS model and Architectral Spport Instrctor: Chengy Song Slide contribtions from Nael Ab-Ghazaleh, Harsha Madhyvasta and Zhiyn Qian Last time/today

More information

Lecture 6 (cont.): Semaphores and Monitors

Lecture 6 (cont.): Semaphores and Monitors Project 1 Due Thursday 10/20 Lecture 6 (cont.): Semaphores and Monitors CSE 120: Principles of Operating Systems Alex C. Snoeren Higher-Level Synchronization We looked at using locks to provide mutual

More information

CS 153 Design of Operating Systems

CS 153 Design of Operating Systems CS 153 Design of Operating Systems Spring 18 Lectre 26: Dynamic Memory (2) Instrctor: Chengy Song Slide contribtions from Nael Ab-Ghazaleh, Harsha Madhyvasta and Zhiyn Qian Some slides modified from originals

More information

CS 153 Design of Operating Systems

CS 153 Design of Operating Systems CS 153 Design of Operating Systems Spring 18 Lectre 23: File Systems (2) Instrctor: Chengy Song Slide contribtions from Nael Ab-Ghazaleh, Harsha Madhyvasta and Zhiyn Qian Last time Abstractions for the

More information

CS 153 Design of Operating Systems

CS 153 Design of Operating Systems CS 153 Design of Operating Systems Spring 18 Lectre 25: Dynamic Memory (1) Instrctor: Chengy Song Slide contribtions from Nael Ab-Ghazaleh, Harsha Madhyvasta and Zhiyn Qian Some slides modified from originals

More information

CS 153 Design of Operating Systems Spring 18

CS 153 Design of Operating Systems Spring 18 CS 153 Design of Operating Systems Spring 18 Lectre 2: Historical Perspective Instrctor: Chengy Song Slide contribtions from Nael Ab-Ghazaleh, Harsha Madhyvasta and Zhiyn Qian Last time What is an OS?

More information

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

Operating Systems. Operating Systems Summer 2017 Sina Meraji U of T Operating Systems Operating Systems Summer 2017 Sina Meraji U of T More Special Instructions Swap (or Exchange) instruction Operates on two words atomically Can also be used to solve critical section problem

More information

Operating Systems ECE344

Operating Systems ECE344 Operating Systems ECE344 Ding Yuan Announcement & Reminder Lab 0 mark posted on Piazza Great job! One problem: compilation error I fixed some for you this time, but won t do it next time Make sure you

More information

CS 153 Design of Operating Systems

CS 153 Design of Operating Systems CS 53 Design of Operating Systems Spring 8 Lectre 6: Paging Instrctor: Chengy Song Slide contribtions from Nael Ab-Ghazaleh, Harsha Madhyvasta and Zhiyn Qian Some slides modified from originals by Dave

More information

Opera&ng Systems ECE344

Opera&ng Systems ECE344 Opera&ng Systems ECE344 Lecture 6: Synchroniza&on (II) Semaphores and Monitors Ding Yuan Higher- Level Synchroniza&on We looked at using locks to provide mutual exclusion Locks work, but they have some

More information

CS 153 Design of Operating Systems Spring 18

CS 153 Design of Operating Systems Spring 18 CS 53 Design of Operating Systems Spring 8 Lectre 2: Virtal Memory Instrctor: Chengy Song Slide contribtions from Nael Ab-Ghazaleh, Harsha Madhyvasta and Zhiyn Qian Recap: cache Well-written programs exhibit

More information

CSE 120 Principles of Operating Systems Spring 2016

CSE 120 Principles of Operating Systems Spring 2016 CSE 120 Principles of Operating Systems Spring 2016 Semaphores and Monitors Higher-Level Synchronization We looked at using locks to provide mutual exclusion Locks work, but they have limited semantics

More information

CS 153 Design of Operating Systems

CS 153 Design of Operating Systems CS 53 Design of Operating Systems Spring 8 Lectre 9: Locality and Cache Instrctor: Chengy Song Slide contribtions from Nael Ab-Ghazaleh, Harsha Madhyvasta and Zhiyn Qian Some slides modified from originals

More information

CS 153 Design of Operating Systems

CS 153 Design of Operating Systems CS 153 Design of Operating Systems Spring 18 Lectre 18: Memory Hierarchy Instrctor: Chengy Song Slide contribtions from Nael Ab-Ghazaleh, Harsha Madhyvasta and Zhiyn Qian Some slides modified from originals

More information

CS 318 Principles of Operating Systems

CS 318 Principles of Operating Systems CS 318 Principles of Operating Systems Fall 2017 Lecture 7: Semaphores and Monitors Ryan Huang Higher-Level Synchronization We looked at using locks to provide mutual exclusion Locks work, but they have

More information

Semaphores. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Semaphores. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University Semaphores Jinkyu Jeong (jinkyu@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu EEE3052: Introduction to Operating Systems, Fall 2017, Jinkyu Jeong (jinkyu@skku.edu) Synchronization

More information

CS 153 Design of Operating Systems

CS 153 Design of Operating Systems CS 153 Design of Operating Systems Spring 18 Lectre 17: Advanced Paging Instrctor: Chengy Song Slide contribtions from Nael Ab-Ghazaleh, Harsha Madhyvasta and Zhiyn Qian Some slides modified from originals

More information

Dealing with Issues for Interprocess Communication

Dealing with Issues for Interprocess Communication Dealing with Issues for Interprocess Communication Ref Section 2.3 Tanenbaum 7.1 Overview Processes frequently need to communicate with other processes. In a shell pipe the o/p of one process is passed

More information

CS 318 Principles of Operating Systems

CS 318 Principles of Operating Systems CS 318 Principles of Operating Systems Fall 2018 Lecture 7: Semaphores and Monitors Ryan Huang Slides adapted from Geoff Voelker s lectures Administrivia HW2 is out Do the exercise to check your understanding

More information

CS 153 Design of Operating Systems Winter 2016

CS 153 Design of Operating Systems Winter 2016 CS 153 Design of Operating Systems Winter 2016 Lecture 7: Synchronization Administrivia Homework 1 Due today by the end of day Hopefully you have started on project 1 by now? Kernel-level threads (preemptable

More information

Synchronization I. Jo, Heeseung

Synchronization I. Jo, Heeseung Synchronization I Jo, Heeseung Today's Topics Synchronization problem Locks 2 Synchronization Threads cooperate in multithreaded programs To share resources, access shared data structures Also, to coordinate

More information

Making Full Use of Multi-Core ECUs with AUTOSAR Basic Software Distribution

Making Full Use of Multi-Core ECUs with AUTOSAR Basic Software Distribution Making Fll Use of Mlti-Core ECUs with AUTOSAR Basic Software Distribtion Webinar V0.1 2018-09-07 Agenda Motivation for Mlti-Core AUTOSAR Standard: SWC-Split MICROSAR Extension: BSW-Split BSW-Split: Technical

More information

CSE 153 Design of Operating Systems

CSE 153 Design of Operating Systems CSE 153 Design of Operating Systems Winter 19 Lecture 7/8: Synchronization (1) Administrivia How is Lab going? Be prepared with questions for this weeks Lab My impression from TAs is that you are on track

More information

Review Multicycle: What is Happening. Controlling The Multicycle Design

Review Multicycle: What is Happening. Controlling The Multicycle Design Review lticycle: What is Happening Reslt Zero Op SrcA SrcB Registers Reg Address emory em Data Sign etend Shift left Sorce A B Ot [-6] [5-] [-6] [5-] [5-] Instrction emory IR RegDst emtoreg IorD em em

More information

Lecture 5: Synchronization w/locks

Lecture 5: Synchronization w/locks Lecture 5: Synchronization w/locks CSE 120: Principles of Operating Systems Alex C. Snoeren Lab 1 Due 10/19 Threads Are Made to Share Global variables and static objects are shared Stored in the static

More information

Operating Systems. Synchronization

Operating Systems. Synchronization Operating Systems Fall 2014 Synchronization Myungjin Lee myungjin.lee@ed.ac.uk 1 Temporal relations Instructions executed by a single thread are totally ordered A < B < C < Absent synchronization, instructions

More information

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

CSE 451: Operating Systems Winter Lecture 7 Synchronization. Steve Gribble. Synchronization. Threads cooperate in multithreaded programs CSE 451: Operating Systems Winter 2005 Lecture 7 Synchronization Steve Gribble Synchronization Threads cooperate in multithreaded programs to share resources, access shared data structures e.g., threads

More information

EXAMINATIONS 2010 END OF YEAR NWEN 242 COMPUTER ORGANIZATION

EXAMINATIONS 2010 END OF YEAR NWEN 242 COMPUTER ORGANIZATION EXAINATIONS 2010 END OF YEAR COPUTER ORGANIZATION Time Allowed: 3 Hors (180 mintes) Instrctions: Answer all qestions. ake sre yor answers are clear and to the point. Calclators and paper foreign langage

More information

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

Synchronization I. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University Synchronization I Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Today s Topics Synchronization problem Locks 2 Synchronization Threads cooperate

More information

Chapter 5: Process Synchronization. Operating System Concepts Essentials 2 nd Edition

Chapter 5: Process Synchronization. Operating System Concepts Essentials 2 nd Edition Chapter 5: Process Synchronization Silberschatz, Galvin and Gagne 2013 Chapter 5: Process Synchronization Background The Critical-Section Problem Peterson s Solution Synchronization Hardware Mutex Locks

More information

VirtuOS: an operating system with kernel virtualization

VirtuOS: an operating system with kernel virtualization VirtOS: an operating system with kernel virtalization Rslan Nikolaev, Godmar Back SOSP '13 Proceedings of the Twenty-Forth ACM Symposim on Oper ating Systems Principles 이영석, 신현호, 박재완 Index Motivation Design

More information

Synchronization. Dr. Yingwu Zhu

Synchronization. Dr. Yingwu Zhu Synchronization Dr. Yingwu Zhu Synchronization Threads cooperate in multithreaded programs To share resources, access shared data structures Threads accessing a memory cache in a Web server To coordinate

More information

The Disciplined Flood Protocol in Sensor Networks

The Disciplined Flood Protocol in Sensor Networks The Disciplined Flood Protocol in Sensor Networks Yong-ri Choi and Mohamed G. Goda Department of Compter Sciences The University of Texas at Astin, U.S.A. fyrchoi, godag@cs.texas.ed Hssein M. Abdel-Wahab

More information

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

CSE 451: Operating Systems Winter Lecture 7 Synchronization. Hank Levy 412 Sieg Hall CSE 451: Operating Systems Winter 2003 Lecture 7 Synchronization Hank Levy Levy@cs.washington.edu 412 Sieg Hall Synchronization Threads cooperate in multithreaded programs to share resources, access shared

More information

Putting the dynamic into software security testing

Putting the dynamic into software security testing Ptting the dynamic into software secrity testing Detecting and Addressing Cybersecrity Isses V1.1 2018-03-05 Code ahead! 2 Atomated vlnerability detection and triage + = 3 How did we get here? Vector was

More information

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

Synchronization. CSE 2431: Introduction to Operating Systems Reading: Chapter 5, [OSC] (except Section 5.10) Synchronization CSE 2431: Introduction to Operating Systems Reading: Chapter 5, [OSC] (except Section 5.10) 1 Outline Critical region and mutual exclusion Mutual exclusion using busy waiting Sleep and

More information

CS370 Operating Systems

CS370 Operating Systems CS370 Operating Systems Colorado State University Yashwant K Malaiya Spring 1018 L11 Synchronization Slides based on Text by Silberschatz, Galvin, Gagne Various sources 1 1 FAQ Multilevel feedback queue:

More information

Concept of a process

Concept of a process Concept of a process In the context of this course a process is a program whose execution is in progress States of a process: running, ready, blocked Submit Ready Running Completion Blocked Concurrent

More information

Lesson 6: Process Synchronization

Lesson 6: Process Synchronization Lesson 6: Process Synchronization Chapter 5: Process Synchronization Background The Critical-Section Problem Peterson s Solution Synchronization Hardware Mutex Locks Semaphores Classic Problems of Synchronization

More information

CAPL Scripting Quickstart

CAPL Scripting Quickstart CAPL Scripting Qickstart CAPL (Commnication Access Programming Langage) For CANalyzer and CANoe V1.01 2015-12-03 Agenda Important information before getting started 3 Visal Seqencer (GUI based programming

More information

The single-cycle design from last time

The single-cycle design from last time lticycle path Last time we saw a single-cycle path and control nit for or simple IPS-based instrction set. A mlticycle processor fies some shortcomings in the single-cycle CPU. Faster instrctions are not

More information

Chapter 6: Synchronization. Operating System Concepts 8 th Edition,

Chapter 6: Synchronization. Operating System Concepts 8 th Edition, Chapter 6: Synchronization, Silberschatz, Galvin and Gagne 2009 Outline Background The Critical-Section Problem Peterson s Solution Synchronization Hardware Semaphores Classic Problems of Synchronization

More information

The final datapath. M u x. Add. 4 Add. Shift left 2. PCSrc. RegWrite. MemToR. MemWrite. Read data 1 I [25-21] Instruction. Read. register 1 Read.

The final datapath. M u x. Add. 4 Add. Shift left 2. PCSrc. RegWrite. MemToR. MemWrite. Read data 1 I [25-21] Instruction. Read. register 1 Read. The final path PC 4 Add Reg Shift left 2 Add PCSrc Instrction [3-] Instrction I [25-2] I [2-6] I [5 - ] register register 2 register 2 Registers ALU Zero Reslt ALUOp em Data emtor RegDst ALUSrc em I [5

More information

CS370 Operating Systems

CS370 Operating Systems CS370 Operating Systems Colorado State University Yashwant K Malaiya Fall 2017 Lecture 11 Slides based on Text by Silberschatz, Galvin, Gagne Various sources 1 1 FAQ Multilevel Feedback Queue: Q0, Q1,

More information

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

Chapter 5: Process Synchronization. Operating System Concepts 9 th Edition Chapter 5: Process Synchronization Silberschatz, Galvin and Gagne 2013 Chapter 5: Process Synchronization Background The Critical-Section Problem Peterson s Solution Synchronization Hardware Mutex Locks

More information

Dynamic Maintenance of Majority Information in Constant Time per Update? Gudmund S. Frandsen and Sven Skyum BRICS 1 Department of Computer Science, Un

Dynamic Maintenance of Majority Information in Constant Time per Update? Gudmund S. Frandsen and Sven Skyum BRICS 1 Department of Computer Science, Un Dynamic Maintenance of Majority Information in Constant Time per Update? Gdmnd S. Frandsen and Sven Skym BRICS 1 Department of Compter Science, University of arhs, Ny Mnkegade, DK-8000 arhs C, Denmark

More information

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

Background. The Critical-Section Problem Synchronisation Hardware Inefficient Spinning Semaphores Semaphore Examples Scheduling. Background The Critical-Section Problem Background Race Conditions Solution Criteria to Critical-Section Problem Peterson s (Software) Solution Concurrent access to shared data may result in data inconsistency

More information

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

10/17/ Gribble, Lazowska, Levy, Zahorjan 2. 10/17/ Gribble, Lazowska, Levy, Zahorjan 4 Temporal relations CSE 451: Operating Systems Autumn 2010 Module 7 Synchronization Instructions executed by a single thread are totally ordered A < B < C < Absent synchronization, instructions executed

More information

Chapter 6: Process Synchronization

Chapter 6: Process Synchronization Chapter 6: Process Synchronization Objectives Introduce Concept of Critical-Section Problem Hardware and Software Solutions of Critical-Section Problem Concept of Atomic Transaction Operating Systems CS

More information

Pipelined van Emde Boas Tree: Algorithms, Analysis, and Applications

Pipelined van Emde Boas Tree: Algorithms, Analysis, and Applications This fll text paper was peer reviewed at the direction of IEEE Commnications Society sbject matter experts for pblication in the IEEE INFOCOM 007 proceedings Pipelined van Emde Boas Tree: Algorithms, Analysis,

More information

Process Synchronization Mechanisms

Process Synchronization Mechanisms Process Synchronization Mechanisms Tom Kelliher, CS 311 Mar 19, 2012 Announcements: From last time: 1. CPU scheduling. Outline: 1. Critical sections and cooperating processes. 2. Cooperating processes

More information

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

CS 31: Introduction to Computer Systems : Threads & Synchronization April 16-18, 2019 CS 31: Introduction to Computer Systems 22-23: Threads & Synchronization April 16-18, 2019 Making Programs Run Faster We all like how fast computers are In the old days (1980 s - 2005): Algorithm too slow?

More information

CSE 451: Operating Systems Winter Synchronization. Gary Kimura

CSE 451: Operating Systems Winter Synchronization. Gary Kimura CSE 451: Operating Systems Winter 2013 Synchronization Gary Kimura Synchronization Threads cooperate in multithreaded programs to share resources, access shared data structures e.g., threads accessing

More information

CSE 153 Design of Operating Systems Fall 2018

CSE 153 Design of Operating Systems Fall 2018 CSE 153 Design of Operating Systems Fall 2018 Lecture 5: Threads/Synchronization Implementing threads l Kernel Level Threads l u u All thread operations are implemented in the kernel The OS schedules all

More information

EECS 482 Introduction to Operating Systems

EECS 482 Introduction to Operating Systems EECS 482 Introduction to Operating Systems Winter 2018 Harsha V. Madhyastha Recap Multi-threaded code with monitors: Locks for mutual exclusion Condition variables for ordering constraints Every thread

More information

CSE 120 Principles of Operating Systems Spring 2016

CSE 120 Principles of Operating Systems Spring 2016 CSE 120 Principles of Operating Systems Spring 2016 Using Semaphores and Condition Variables Higher-Level Synchronization We looked at using locks to provide mutual exclusion Locks work, but they have

More information

The extra single-cycle adders

The extra single-cycle adders lticycle Datapath As an added bons, we can eliminate some of the etra hardware from the single-cycle path. We will restrict orselves to sing each fnctional nit once per cycle, jst like before. Bt since

More information

Chapter 6: Synchronization. Chapter 6: Synchronization. 6.1 Background. Part Three - Process Coordination. Consumer. Producer. 6.

Chapter 6: Synchronization. Chapter 6: Synchronization. 6.1 Background. Part Three - Process Coordination. Consumer. Producer. 6. Part Three - Process Coordination Chapter 6: Synchronization 6.1 Background Concurrent access to shared data may result in data inconsistency Maintaining data consistency requires mechanisms to ensure

More information

The multicycle datapath. Lecture 10 (Wed 10/15/2008) Finite-state machine for the control unit. Implementing the FSM

The multicycle datapath. Lecture 10 (Wed 10/15/2008) Finite-state machine for the control unit. Implementing the FSM Lectre (Wed /5/28) Lab # Hardware De Fri Oct 7 HW #2 IPS programming, de Wed Oct 22 idterm Fri Oct 2 IorD The mlticycle path SrcA Today s objectives: icroprogramming Etending the mlti-cycle path lti-cycle

More information

Recap: Thread. What is it? What does it need (thread private)? What for? How to implement? Independent flow of control. Stack

Recap: Thread. What is it? What does it need (thread private)? What for? How to implement? Independent flow of control. Stack What is it? Recap: Thread Independent flow of control What does it need (thread private)? Stack What for? Lightweight programming construct for concurrent activities How to implement? Kernel thread vs.

More information

Chapter 6: Process Synchronization

Chapter 6: Process Synchronization Chapter 6: Process Synchronization Chapter 6: Synchronization 6.1 Background 6.2 The Critical-Section Problem 6.3 Peterson s Solution 6.4 Synchronization Hardware 6.5 Mutex Locks 6.6 Semaphores 6.7 Classic

More information

POWER-OF-2 BOUNDARIES

POWER-OF-2 BOUNDARIES Warren.3.fm Page 5 Monday, Jne 17, 5:6 PM CHAPTER 3 POWER-OF- BOUNDARIES 3 1 Ronding Up/Down to a Mltiple of a Known Power of Ronding an nsigned integer down to, for eample, the net smaller mltiple of

More information

Synchronization. CS 475, Spring 2018 Concurrent & Distributed Systems

Synchronization. CS 475, Spring 2018 Concurrent & Distributed Systems Synchronization CS 475, Spring 2018 Concurrent & Distributed Systems Review: Threads: Memory View code heap data files code heap data files stack stack stack stack m1 m1 a1 b1 m2 m2 a2 b2 m3 m3 a3 m4 m4

More information

CS3733: Operating Systems

CS3733: Operating Systems Outline CS3733: Operating Systems Topics: Synchronization, Critical Sections and Semaphores (SGG Chapter 6) Instructor: Dr. Tongping Liu 1 Memory Model of Multithreaded Programs Synchronization for coordinated

More information

5 Performance Evaluation

5 Performance Evaluation 5 Performance Evalation his chapter evalates the performance of the compared to the MIP, and FMIP individal performances. We stdy the packet loss and the latency to restore the downstream and pstream of

More information

Lecture. DM510 - Operating Systems, Weekly Notes, Week 11/12, 2018

Lecture. DM510 - Operating Systems, Weekly Notes, Week 11/12, 2018 Lecture In the lecture on March 13 we will mainly discuss Chapter 6 (Process Scheduling). Examples will be be shown for the simulation of the Dining Philosopher problem, a solution with monitors will also

More information

Introduction to OS Synchronization MOS 2.3

Introduction to OS Synchronization MOS 2.3 Introduction to OS Synchronization MOS 2.3 Mahmoud El-Gayyar elgayyar@ci.suez.edu.eg Mahmoud El-Gayyar / Introduction to OS 1 Challenge How can we help processes synchronize with each other? E.g., how

More information

Requirements Engineering. Objectives. System requirements. Types of requirements. FAQS about requirements. Requirements problems

Requirements Engineering. Objectives. System requirements. Types of requirements. FAQS about requirements. Requirements problems Reqirements Engineering Objectives An introdction to reqirements Gerald Kotonya and Ian Sommerville To introdce the notion of system reqirements and the reqirements process. To explain how reqirements

More information

Chapter 6: Process Synchronization. Operating System Concepts 8 th Edition,

Chapter 6: Process Synchronization. Operating System Concepts 8 th Edition, Chapter 6: Process Synchronization, Silberschatz, Galvin and Gagne 2009 Module 6: Process Synchronization Background The Critical-Section Problem Peterson s Solution Synchronization Hardware Semaphores

More information

Chapter 6: Process Synchronization

Chapter 6: Process Synchronization Chapter 6: Process Synchronization Chapter 6: Process Synchronization Background The Critical-Section Problem Peterson s Solution Synchronization Hardware Mutex Locks Semaphores Classic Problems of Synchronization

More information

CS 153 Design of Operating Systems Spring 18

CS 153 Design of Operating Systems Spring 18 CS 153 Design of Operating Systems Spring 18 Lectre 1: Corse Introdction Instrctor: Chengy Song Slide contribtions from Nael Ab-Ghazaleh, Harsha Madhyvasta and Zhiyn Qian Teaching Staff Chengy Song I am

More information

Example Threads. compile: gcc mythread.cc -o mythread -lpthread What is the output of this program? #include <pthread.h> #include <stdio.

Example Threads. compile: gcc mythread.cc -o mythread -lpthread What is the output of this program? #include <pthread.h> #include <stdio. Example Threads #include #include int num = 0; void *add_one(int *thread_num) { num++; printf("thread %d num = %d\n", *thread_num, num); } void main() { pthread_t thread; int my_id

More information

Tdb: A Source-level Debugger for Dynamically Translated Programs

Tdb: A Source-level Debugger for Dynamically Translated Programs Tdb: A Sorce-level Debgger for Dynamically Translated Programs Naveen Kmar, Brce R. Childers, and Mary Lo Soffa Department of Compter Science University of Pittsbrgh Pittsbrgh, Pennsylvania 15260 {naveen,

More information

DSCS6020: SQLite and RSQLite

DSCS6020: SQLite and RSQLite DSCS6020: SQLite and RSQLite SQLite History SQlite is an open sorce embedded database, meaning that it doesn t have a separate server process. Reads and writes to ordinary disk files. The original implementation

More information

Isilon InsightIQ. Version 2.5. User Guide

Isilon InsightIQ. Version 2.5. User Guide Isilon InsightIQ Version 2.5 User Gide Pblished March, 2014 Copyright 2010-2014 EMC Corporation. All rights reserved. EMC believes the information in this pblication is accrate as of its pblication date.

More information

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

Operating Systems. Lecture 4 - Concurrency and Synchronization. Master of Computer Science PUF - Hồ Chí Minh 2016/2017 Operating Systems Lecture 4 - Concurrency and Synchronization Adrien Krähenbühl Master of Computer Science PUF - Hồ Chí Minh 2016/2017 Mutual exclusion Hardware solutions Semaphores IPC: Message passing

More information

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

Operating Systems. Designed and Presented by Dr. Ayman Elshenawy Elsefy Operating Systems Designed and Presented by Dr. Ayman Elshenawy Elsefy Dept. of Systems & Computer Eng.. AL-AZHAR University Website : eaymanelshenawy.wordpress.com Email : eaymanelshenawy@yahoo.com Reference

More information

CPSC/ECE 3220 Fall 2017 Exam Give the definition (note: not the roles) for an operating system as stated in the textbook. (2 pts.

CPSC/ECE 3220 Fall 2017 Exam Give the definition (note: not the roles) for an operating system as stated in the textbook. (2 pts. CPSC/ECE 3220 Fall 2017 Exam 1 Name: 1. Give the definition (note: not the roles) for an operating system as stated in the textbook. (2 pts.) Referee / Illusionist / Glue. Circle only one of R, I, or G.

More information

Today s Lecture. Software Architecture. Lecture 27: Introduction to Software Architecture. Introduction and Background of

Today s Lecture. Software Architecture. Lecture 27: Introduction to Software Architecture. Introduction and Background of Today s Lectre Lectre 27: Introdction to Software Architectre Kenneth M. Anderson Fondations of Software Engineering CSCI 5828 - Spring Semester, 1999 Introdction and Backgrond of Software Architectre

More information

CSE 141 Computer Architecture Summer Session I, Lectures 10 Advanced Topics, Memory Hierarchy and Cache. Pramod V. Argade

CSE 141 Computer Architecture Summer Session I, Lectures 10 Advanced Topics, Memory Hierarchy and Cache. Pramod V. Argade CSE 141 Compter Architectre Smmer Session I, 2004 Lectres 10 Advanced Topics, emory Hierarchy and Cache Pramod V. Argade CSE141: Introdction to Compter Architectre Instrctor: TA: Pramod V. Argade (p2argade@cs.csd.ed)

More information

Synchronization Basic Problem:

Synchronization Basic Problem: Synchronization Synchronization Basic Problem: If two concurrent processes are accessing a shared variable, and that variable is read, modified, and written by those processes, then the variable must be

More information

1048: Computer Organization

1048: Computer Organization 48: Compter Organization Lectre 5 Datapath and Control Lectre5B - mlticycle implementation (cwli@twins.ee.nct.ed.tw) 5B- Recap: A Single-Cycle Processor PCSrc 4 Add Shift left 2 Add ALU reslt PC address

More information

Advanced Operating Systems (CS 202) Memory Consistency, Cache Coherence and Synchronization

Advanced Operating Systems (CS 202) Memory Consistency, Cache Coherence and Synchronization Advanced Operating Systems (CS 202) Memory Consistency, Cache Coherence and Synchronization Jan, 27, 2017 (some cache coherence slides adapted from Ian Watson; some memory consistency slides from Sarita

More information

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

Background. Old Producer Process Code. Improving the Bounded Buffer. Old Consumer Process Code Old Producer Process Code Concurrent access to shared data may result in data inconsistency Maintaining data consistency requires mechanisms to ensure the orderly execution of cooperating processes Our

More information

Chapter 5: Process Synchronization

Chapter 5: Process Synchronization Chapter 5: Process Synchronization Silberschatz, Galvin and Gagne 2013 Operating System Concepts 9th Edition Chapter 5: Process Synchronization Background The Critical-Section Problem Peterson s Solution

More information

Pipelining. Chapter 4

Pipelining. Chapter 4 Pipelining Chapter 4 ake processor rns faster Pipelining is an implementation techniqe in which mltiple instrctions are overlapped in eection Key of making processor fast Pipelining Single cycle path we

More information

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

Chapter 5: Process Synchronization. Operating System Concepts 9 th Edition Chapter 5: Process Synchronization Silberschatz, Galvin and Gagne 2013 Chapter 5: Process Synchronization Background The Critical-Section Problem Peterson s Solution Synchronization Hardware Mutex Locks

More information

TDT4255 Friday the 21st of October. Real world examples of pipelining? How does pipelining influence instruction

TDT4255 Friday the 21st of October. Real world examples of pipelining? How does pipelining influence instruction Review Friday the 2st of October Real world eamples of pipelining? How does pipelining pp inflence instrction latency? How does pipelining inflence instrction throghpt? What are the three types of hazard

More information

Lecture 4: Routing. CSE 222A: Computer Communication Networks Alex C. Snoeren. Thanks: Amin Vahdat

Lecture 4: Routing. CSE 222A: Computer Communication Networks Alex C. Snoeren. Thanks: Amin Vahdat Lectre 4: Roting CSE 222A: Compter Commnication Networks Alex C. Snoeren Thanks: Amin Vahdat Lectre 4 Overview Pop qiz Paxon 95 discssion Brief intro to overlay and active networking 2 End-to-End Roting

More information

Millimeter-Wave Multi-Hop Wireless Backhauling for 5G Cellular Networks

Millimeter-Wave Multi-Hop Wireless Backhauling for 5G Cellular Networks 2017 IEEE 85th Vehiclar Technology Conference (VTC-Spring) Millimeter-Wave Mlti-Hop Wireless Backhaling for 5G Celllar Networks B. P. S. Sahoo, Chn-Han Yao, and Hng-Y Wei Gradate Institte of Electrical

More information

Synchronization Spinlocks - Semaphores

Synchronization Spinlocks - Semaphores CS 4410 Operating Systems Synchronization Spinlocks - Semaphores Summer 2013 Cornell University 1 Today How can I synchronize the execution of multiple threads of the same process? Example Race condition

More information

Process Management And Synchronization

Process Management And Synchronization Process Management And Synchronization In a single processor multiprogramming system the processor switches between the various jobs until to finish the execution of all jobs. These jobs will share the

More information