Thread Synchronization

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.
Operating Systems Part III: Process Management (Process Synchronization)
CS492B Analysis of Concurrent Programs Lock Basics Jaehyuk Huh Computer Science, KAIST.
Previously… Processes –Process States –Context Switching –Process Queues Threads –Thread Mappings Scheduling –FCFS –SJF –Priority scheduling –Round Robin.
Chapter 6: Process Synchronization
Background Concurrent access to shared data can lead to inconsistencies Maintaining data consistency among cooperating processes is critical What is wrong.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 5: 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.
1 CENG334 Introduction to Operating Systems Erol Sahin Dept of Computer Eng. Middle East Technical University Ankara, TURKEY URL:
Process Synchronization. Module 6: Process Synchronization Background The Critical-Section Problem Peterson’s Solution Synchronization Hardware Semaphores.
Mutual Exclusion.
Secure Operating Systems Lesson 5: Shared Objects.
Operating Systems ECE344 Ding Yuan Synchronization (I) -- Critical region and lock Lecture 5: Synchronization (I) -- Critical region and lock.
1 Synchronization Coordinating the Activity of Mostly Independent Entities.
5.6 Semaphores Semaphores –Software construct that can be used to enforce mutual exclusion –Contains a protected variable Can be accessed only via wait.
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.
Monitors CSCI 444/544 Operating Systems Fall 2008.
Synchronization (other solutions …). Announcements Assignment 2 is graded Project 1 is due today.
Race Conditions CS550 Operating Systems. Review So far, we have discussed Processes and Threads and talked about multithreading and MPI processes by example.
U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Emery Berger University of Massachusetts, Amherst Operating Systems CMPSCI 377 Lecture.
Instructor: Umar KalimNUST Institute of Information Technology Operating Systems Process Synchronization.
Discussion Week 3 TA: Kyle Dewey. Overview Concurrency overview Synchronization primitives Semaphores Locks Conditions Project #1.
Synchronization Andy Wang Operating Systems COP 4610 / CGS 5765.
Implementing Synchronization. Synchronization 101 Synchronization constrains the set of possible interleavings: Threads “agree” to stay out of each other’s.
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.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Mutual Exclusion.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts Essentials – 9 th Edition Chapter 5: Process Synchronization.
Kernel Locking Techniques by Robert Love presented by Scott Price.
Chapter 6 – Process Synchronisation (Pgs 225 – 267)
Operating Systems CMPSC 473 Mutual Exclusion Lecture 11: October 5, 2010 Instructor: Bhuvan Urgaonkar.
CS399 New Beginnings Jonathan Walpole. 2 Concurrent Programming & Synchronization Primitives.
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-5 Process Synchronization Department of Computer Science and Software.
U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Synchronization Emery Berger and Mark Corner University.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 6: Process Synchronization.
Synchronization CSCI 3753 Operating Systems Spring 2005 Prof. Rick Han.
CSCI1600: Embedded and Real Time Software Lecture 17: Concurrent Programming Steven Reiss, Fall 2015.
Critical Section Tools (HW interface) locks implemented in ISA – T&S, CAS (O.S. )Semaphores – Counting and Binary (a.k.a a mutex lock) (Augmented O.S.)
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 6: Process Synchronization.
Implementing Mutual Exclusion Andy Wang Operating Systems COP 4610 / CGS 5765.
Mutual Exclusion -- Addendum. Mutual Exclusion in Critical Sections.
Synchronization Questions answered in this lecture: Why is synchronization necessary? What are race conditions, critical sections, and atomic operations?
December 1, 2006©2006 Craig Zilles1 Threads & Atomic Operations in Hardware  Previously, we introduced multi-core parallelism & cache coherence —Today.
Kernel Synchronization David Ferry, Chris Gill CSE 522S - Advanced Operating Systems Washington University in St. Louis St. Louis, MO
Sarah Diesburg Operating Systems COP 4610
CS703 – Advanced Operating Systems
Background on the need for Synchronization
Synchronization and Scheduling
Atomic Operations in Hardware
Atomic Operations in Hardware
Chapter 5: Process Synchronization
Topic 6 (Textbook - Chapter 5) Process Synchronization
Critical section problem
Coordination Lecture 5.
Grades.
Chapter 6: Process Synchronization
CSCI1600: Embedded and Real Time Software
Implementing Mutual Exclusion
Kernel Synchronization II
CSE 153 Design of Operating Systems Winter 19
CSE 153 Design of Operating Systems Winter 2019
CS333 Intro to Operating Systems
Chapter 6: Synchronization Tools
CSCI1600: Embedded and Real Time Software
Process/Thread Synchronization (Part 2)
CSE 542: Operating Systems
Threads CSE451 Andrew Whitaker TODO: print handouts for AspectRatio.
Sarah Diesburg Operating Systems CS 3430
Presentation transcript:

Thread Synchronization Section 5 Thread Synchronization February 17th, 2016 Taught by Joshua Don

Project Tips Keep the spec and your design doc handy Make a plan for breaking up the work Pair programming, group programming Work backwards from the due date to decide when you want to complete each task by You have the source code for all the tests Make a separate branch (don’t always push to master!) git checkout –b dev git checkout master git branch -v git merge dev

Project Tips Cont. Task difficulty Really important files for proj1 that you should understand completely: timer.c synch.c/h thread.c/h Easy Hard Task difficulty Efficient alarm clock Priority scheduling + priority donation MLFQS Staff solution: 500 lines Personal: 363 lines

Atomic operations Atomic operation: An operation that either executes completely or not at all. Cannot be interrupted in the middle of performing its function. Is i++ atomic? load i increment value store i Race condition

Atomic operations i=0; i++; Thread 1 Thread 2 load i increment value store i Race condition

Atomic operations i=0; i++; Thread 2 load i Thread 1 increment value store i Thread 1 Race condition

Atomic operations i=0; i++; Thread 2 load i increment value store i Race condition Thread 1

Atomic operations i=0; i++; load i Thread 2 increment value store i Race condition Thread 1

Atomic operations i=0; i++; load i increment value store i Thread 1 Race condition Thread 1 Thread 2

Atomic operations i=0; i++; load i increment value store i Thread 2 Race condition Thread 2 Thread 1

Atomic operations i=0; i++; load i increment value store i Thread 1 Race condition Thread 1 Thread 2

Atomic operations i=1 i=0; i++; load i increment value store i Race condition Thread 1 Thread 2 i=1

Test and Set Lock acquire Lock release Test_and_set: An atomic operation that can be used to build a lock. int test_and_set(int *value) { int result = *value; *value = 1; return result; } Simple lock using test_and_set Busy wait int value = 0; ... while(test_and_set(&value)); // critical section value = 0; Lock acquire Lock release

Critical Sections Critical Section: A protected region of code. It requires mutual exclusion of access. i=0 lock_acquire(my_lock); i++; lock_release(my_lock);

Demo