Page 1. Why allow cooperating threads?" Threaded Web Server"

Similar documents
Page 1. Recap: ATM Bank Server" Recap: Challenge of Threads"

Page 1. Challenges" Concurrency" CS162 Operating Systems and Systems Programming Lecture 4. Synchronization, Atomic operations, Locks"

Page 1. CS162 Operating Systems and Systems Programming Lecture 6. Synchronization. Goals for Today

Page 1. Another Concurrent Program Example" Goals for Today" CS162 Operating Systems and Systems Programming Lecture 4

5. Synchronization. Operating System Concepts with Java 8th Edition Silberschatz, Galvin and Gagn

September 21 st, 2015 Prof. John Kubiatowicz

CS162 Operating Systems and Systems Programming Lecture 6. Synchronization. Review: ThreadFork(): Create a New Thread

CS 162 Operating Systems and Systems Programming Professor: Anthony D. Joseph Spring 2002

Page 1. Review: Execution Stack Example" Review: Execution Stack Example" Review: Execution Stack Example"

Page 1. CS194-3/CS16x Introduction to Systems. Lecture 6. Synchronization primitives, Semaphores, Overview of ACID.

CS162 Operating Systems and Systems Programming Lecture 7. Mutual Exclusion, Semaphores, Monitors, and Condition Variables

Page 1. Goals for Today" Why Processes & Threads?" Putting it together: Process" CS162 Operating Systems and Systems Programming Lecture 3

CS162 Operating Systems and Systems Programming Lecture 7. Synchronization (Continued) Recall: How does Thread get started?

Page 1. Goals for Today" Putting it together: Process" Why Processes & Threads?" CS162 Operating Systems and Systems Programming Lecture 3

Page 1. Execution Stack Example" Execution Stack Example" Execution Stack Example" CS162 Operating Systems and Systems Programming Lecture 2

CS162 Operating Systems and Systems Programming Lecture 7. Concurrency (Continued), Synchronization

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

CS162 Operating Systems and Systems Programming Lecture 3 Concurrency and Thread Dispatching

Today: Synchronization. Recap: Synchronization

Operating Systems (1DT020 & 1TT802) Lecture 6 Process synchronisation : Hardware support, Semaphores, Monitors, and Condition Variables

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

Lecture #7: Implementing Mutual Exclusion

Last Class: CPU Scheduling! Adjusting Priorities in MLFQ!

EECS 482 Introduction to Operating Systems

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

9/17/12! Ion Stoica CS162 UCB Fall 2012!

Goals. Processes and Threads. Concurrency Issues. Concurrency. Interlacing Processes. Abstracting a Process

Page 1. Goals for Today" Recap: Monitors" CS162 Operating Systems and Systems Programming Lecture 7. Semaphores, Conditional Variables, Deadlocks"

Concurrency & Synchronization. COMPSCI210 Recitation 25th Feb 2013 Vamsi Thummala Slides adapted from Landon Cox

Threads and Too Much Milk! CS439: Principles of Computer Systems February 6, 2019

Safety and liveness for critical sections

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

CS162 Operating Systems and Systems Programming Lecture 4. Cooperating Threads. Page 1

September 23 rd, 2015 Prof. John Kubiatowicz

CS162 Operating Systems and Systems Programming Lecture 5. Cooperating Threads. Review: Per Thread State Each Thread has a Thread Control Block (TCB)

Page 1. CS194-3/CS16x Introduction to Systems. Lecture 8. Database concurrency control, Serializability, conflict serializability, 2PL and strict 2PL

Threads and Too Much Milk! CS439: Principles of Computer Systems January 31, 2018

Synchronization. CS61, Lecture 18. Prof. Stephen Chong November 3, 2011

Page 1. Goals for Today" Important Aspects of Memory Multiplexing" Virtualizing Resources" CS162 Operating Systems and Systems Programming Lecture 9

PROCESS SYNCHRONIZATION READINGS: CHAPTER 5

Midterm Exam Solutions and Grading Guidelines March 3, 1999 CS162 Operating Systems

Implementing Mutual Exclusion. Sarah Diesburg Operating Systems CS 3430

Chapter 5: Synchronization 1

Operating Systems. Synchronization

Thread Synchronization: Too Much Milk

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

Page 1. Virtual Machines (Recap)" Nachos: Virtual OS Environment" System Virtual Machines: Layers of OSs"

Midterm Exam March 3, 1999 CS162 Operating Systems

Page 1. Virtual Machines (Recap)" Nachos: Virtual OS Environment (Recap)" System VMs: Layers of OSs (Recap)"

CS162 Operating Systems and Systems Programming Lecture 5. Cooperating Threads. Review: Per Thread State Each Thread has a Thread Control Block (TCB)

2 Threads vs. Processes

Chapter 6: Process [& Thread] Synchronization. CSCI [4 6] 730 Operating Systems. Why does cooperation require synchronization?

Dealing with Issues for Interprocess Communication

! Why is synchronization needed? ! Synchronization Language/Definitions: ! How are locks implemented? Maria Hybinette, UGA

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

CSL373: Lecture 5 Deadlocks (no process runnable) + Scheduling (> 1 process runnable)

Thread Synchronization: Foundations. Properties. Safety properties. Edsger s perspective. Nothing bad happens

Lecture 5: Synchronization w/locks

CSL373: Lecture 7 Advanced Scheduling

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

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

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

CSE 153 Design of Operating Systems

Lecture #7: Shared objects and locks

CS5460: Operating Systems

Processor speed. Concurrency Structure and Interpretation of Computer Programs. Multiple processors. Processor speed. Mike Phillips <mpp>

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

CS 162 Operating Systems and Systems Programming Professor: Anthony D. Joseph Spring 2004

Synchronization I. Jo, Heeseung

Last Class: Synchronization

CS 153 Design of Operating Systems Winter 2016

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

Multiprocessor Systems. Chapter 8, 8.1

Concurrency, Thread. Dongkun Shin, SKKU

Thread-Local. Lecture 27: Concurrency 3. Dealing with the Rest. Immutable. Whenever possible, don t share resources

Problem Set 2. CS347: Operating Systems

Reminder from last time

Threads and concurrency

Threads and concurrency

10/7/13! Anthony D. Joseph and John Canny CS162 UCB Fall 2013! " (0xE0)" " " " (0x70)" " (0x50)"

Thread States, Dispatching, Cooperating Threads. November Winter Term 2008/09 Gerd Liefländer

Need for synchronization: If threads comprise parts of our software systems, then they must communicate.

Deadlock and Monitors. CS439: Principles of Computer Systems September 24, 2018

CS370 Operating Systems

CS Advanced Operating Systems Structures and Implementation Lecture 7. How to work in a group / Synchronization Review.

2 Introduction to Processes

Page 1. CS194-3/CS16x Introduction to Systems. Lecture 22. TCP congestion control, Two-Phase Commit. 3-way handshake. ½ close.

CSE332: Data Abstractions Lecture 22: Shared-Memory Concurrency and Mutual Exclusion. Tyler Robison Summer 2010

CSE 374 Programming Concepts & Tools

Multiprocessor scheduling

Chapter 5 Asynchronous Concurrent Execution

CSCI [4 6] 730 Operating Systems. Example Execution. Process [& Thread] Synchronization. Why does cooperation require synchronization?

Synchronization in Concurrent Programming. Amit Gupta

The concept of concurrency is fundamental to all these areas.

Explain briefly how starvation may occur in process scheduling. (2 marks)

Concurrent & Distributed Systems Supervision Exercises

Advanced Java Programming Course. MultiThreading. By Võ Văn Hải Faculty of Information Technologies Industrial University of Ho Chi Minh City

Page 1. Goals for Today" Recap: Readers/Writers Problem" W

Multiprocessor System. Multiprocessor Systems. Bus Based UMA. Types of Multiprocessors (MPs) Cache Consistency. Bus Based UMA. Chapter 8, 8.

Synchronization II: EventBarrier, Monitor, and a Semaphore. COMPSCI210 Recitation 4th Mar 2013 Vamsi Thummala

Transcription:

Why allow cooperating threads?" CS162 Operating Systems and Systems Programming Lecture 4 Synchronization, Atomic operations, Locks" February 3, 2014! Anthony D Joseph! http://insteecsberkeleyedu/~cs162! People cooperate; computers help/enhance people s lives, so computers must cooperate! By analogy, the non-reproducibility/non-determinism of people is a notable problem for carefully laid plans! Advantage 1: Share resources! One computer, many users! One bank balance, many ATMs!» What if ATMs were only updated at night?! Embedded systems (robot control: coordinate arm & hand)! Advantage 2: Speedup! Overlap I/O and computation! Multiprocessors chop up program into parallel pieces! Advantage 3: Modularity! Chop large problem up into simpler pieces!» To compile, for instance, gcc calls cpp cc1 cc2 as ld!» Makes system easier to extend! Lec 42! Threaded Web Server" Multithreaded version:! serverloop() { connection = AcceptCon(); ThreadCreate(ServiceWebPage(),connection); Advantages of threaded version:! Can share file caches kept in memory, results of CGI scripts, other things! Threads are much cheaper to create than processes, so this has a lower per-request overhead! What if too many requests come in at once?! Lec 43! Thread Pools" Problem with previous version: Unbounded Threads! When web-site becomes too popular throughput sinks! Instead, allocate a bounded pool of threads, representing the maximum level of multiprogramming! Master! Thread! slave(queue) { master() { allocthreads(slave,queue); while(true) { con=dequeue(queue); while(true) { if (con==null) con=acceptcon(); Enqueue(queue,con); sleepon(queue); else wakeup(queue); ServiceWebPage(con); 2/3/14! Anthony D Joseph!!CS162! UCB Spring 2014! Lec 44! queue! Thread Pool! Page 1

ATM Bank Server" ATM server problem:! Service a set of requests! Do so without corrupting database! Don t hand out too much money! Fun Fact: Over 95% of ATMs run WinXP! Lec 45! ATM bank server example" Suppose we wanted to implement a server process to handle requests from an ATM network:!!bankserver() { while (TRUE) { ReceiveRequest(&op, &acctid, &amount); ProcessRequest(op, acctid, amount); ProcessRequest(op, acctid, amount) { if (op == deposit) Deposit(acctId, amount); else if Deposit(acctId, amount) { acct = GetAccount(acctId); /* may use disk I/O */ acct->balance += amount; StoreAccount(acct); /* Involves disk I/O */ How could we speed this up?! More than one request being processed at once! Multiple threads (multi-proc, or overlap comp and I/O)! Lec 46! One thread per request!! Can Threads Help?" Requests proceeds to completion, blocking as required:! Deposit(acctId, amount) { acct = GetAccount(actId); /* May use disk I/O */ acct->balance += amount; StoreAccount(acct); /* Involves disk I/O */! Unfortunately, shared state can get corrupted:!!thread 1!!Thread 2!load r1, acct->balance load r1, acct->balance add r1, amount2 store r1, acct->balance add r1, amount1 store r1, acct->balance Problem is at the lowest level"!!x = 1;!!!! x = y+1;!! y = 2;! y = y*2! x=13" Lec 47! Lec 48! Page 2

Problem is at the lowest level"! y = 2;!!! y = y*2;!! x = 1;! x = y+1;! x=5" Problem is at the lowest level"! y = 2;!!!! x = 1;!! x = y+1;! y= y*2;! x=3" Lec 49! Lec 410! Recap: ATM Bank Server" Recap: Challenge of Threads" Speed up server by using multiple threads (one per request)! Can use multi-processor, or overlap comp and I/O! Requests proceeds to completion, blocking as required:! Deposit(acctId, amount) { acct = GetAccount(actId); /* May use disk I/O */ acct->balance += amount; StoreAccount(acct); /* Involves disk I/O */! ATM server problem:! Service a set of requests! Do so without corrupting database! Don t hand out too much money! Lec 411! Unfortunately, shared state can get corrupted:!!thread 1!!Thread 2!load r1, acct->balance load r1, acct->balance add r1, amount2 store r1, acct->balance add r1, amount1 store r1, acct->balance Lec 412! Page 3

Recap: Problem is at the lowest level"!!x = 1;!!!! x = y+1;!! y = 2;! y = y*2! Recap: Problem is at the lowest level"! y = 2;!!! y = y*2;!! x = 1;! x = y+1;! x=13" Preemption can occur! at any time!! x=5" Preemption can occur! at any time!! Lec 413! Lec 414! Recap: Problem is at the lowest level"! y = 2;!!!! x = 1;!! x = y+1;! y= y*2;! x=3" Preemption can occur! at any time!! Goals for Today" Concurrency examples and sharing! Synchronization! Hardware Support for Synchronization!! Note: Some slides and/or pictures in the following are adapted from slides 2005 Silberschatz, Galvin, and Gagne Slides courtesy of Anthony D Joseph, John Kubiatowicz, AJ Shankar, George Necula, Alex Aiken, Eric Brewer, Ras Bodik, Ion Stoica, Doug Tygar, and David Wagner! Lec 415! Lec 416! Page 4

Correctness Requirements" Threaded programs must work for all interleavings of thread instruction sequences! Cooperating threads inherently non-deterministic and nonreproducible! Really hard to debug unless carefully designed!! Example: Therac-25! Machine for radiation therapy!» Software control of electron accelerator and electron beam/ Xray production!» Software control of dosage! Software errors caused overdoses and the death of several patients!» A series of race conditions on shared variables and poor software design!» They determined that data entry speed during editing was the key factor in producing the error condition: If the prescription data was edited at a fast pace, the overdose occurred! Lec 417! Space Shuttle Example" Original Space Shuttle launch aborted 20 minutes before scheduled launch! Shuttle has five computers:! Four run the Primary Avionics Software System (PASS)!» Asynchronous and real-time!» Runs all of the control systems! PASS» Results synchronized and compared 440 times per second! The Fifth computer is the Backup Flight System (BFS)!» Stays synchronized in case it is needed!» Written by completely different team than PASS! Countdown aborted because BFS disagreed with PASS! A 1/67 chance that PASS was out of sync one cycle! Bug due to modifications in initialization code of PASS!» A delayed init request placed into timer queue!» As a result, timer queue not empty at expected time to force use of hardware clock! Bug not found during extensive simulation! BFS Lec 418! Atomic Operations" To understand a concurrent program, we need to know what the underlying atomic operations are!! Atomic Operation: an operation that always runs to completion or not at all! It is indivisible: it cannot be stopped in the middle and state cannot be modified by someone else in the middle! Fundamental building block if no atomic operations, then have no way for threads to work together! On most machines, memory references and assignments (ie loads and stores) of words are atomic! Many instructions are not atomic! Double-precision floating point store often not atomic! VAX and IBM 360 had an instruction to copy a whole array! Concurrency Challenges" Multiple computations (threads) executing in parallel to! share resources, and/or! share data! Fine grain sharing:! increase concurrency à better performance! more complex! Coarse grain sharing:! Simpler to implement! Lower performance! Examples:! Sharing CPU for 10ms vs 1min! Sharing a database at the row vs table granularity! Lec 419! Lec 420! Page 5

Motivation: Too much milk " Great thing about OS s analogy between problems in OS and problems in real life! Help you understand real life problems better! But, computers are much stupider than people! Example: People need to coordinate:! Definitions" Synchronization: using atomic operations to ensure cooperation between threads! For now, only loads and stores are atomic! We ll show that is hard to build anything useful with only reads and writes! Time" 3:00" Person A" Look in Fridge Out of milk" Person B" Critical Section: piece of code that only one thread can execute at once! 3:05" Leave for store" 3:10" 3:15" 3:20" 3:25" 3:30" Arrive at store" Buy milk" Arrive home, put milk away" Look in Fridge Out of milk" Leave for store" Arrive at store" Buy milk" Arrive home, put milk away" Mutual Exclusion: ensuring that only one thread executes critical section! One thread excludes the other while doing its task! Critical section and mutual exclusion are two ways of describing the same thing! Lec 421! Lec 422! More Definitions" Lock: prevents someone from doing something! Lock before entering critical section and before accessing shared data! Unlock when leaving, after accessing shared data! Wait if locked!» Important idea: all synchronization involves waiting! Example: fix the milk problem by putting a lock on refrigerator! Lock it and take key if you are going to go buy milk! Fixes too much (coarse granularity): roommate angry if only wants orange juice! #$@%@#$@ Too Much Milk: Correctness Properties" Need to be careful about correctness of concurrent programs, since non-deterministic! Always write down desired behavior first! Impulse is to start coding first, then when it doesn t work, pull hair out! Instead, think first, then code! What are the correctness properties for the Too much milk problem?! Never more than one person buys! Someone buys if needed!! Of Course We don t know how to make a lock yet! Restrict ourselves to use only atomic load and store operations as building blocks! Lec 423! Lec 424! Page 6

Too Much Milk: Solution #1" Use a note to avoid buying too much milk:! Leave a note before buying (kind of lock )! Remove note after buying (kind of unlock )! Don t buy if note (wait)! Suppose a computer tries this (remember, only memory read/ write are atomic):! Result?! if (nomilk) { if (nonote) { leave Note; remove note; Lec 425! Too Much Milk: Solution #1" Still too much milk but only occasionally!! Thread A Thread B if (nomilk) if (nonote) { leave Note; remove note;! if (nomilk) if (nonote) { leave Note; Thread can get context switched after checking milk and note but before leaving note!! Solution makes problem worse since fails intermittently! Makes it really hard to debug! Must work despite what the thread dispatcher does!! Lec 426! Too Much Milk: Solution #1½ " Clearly the Note is not quite blocking enough! Let s try to fix this by placing note first! Another try at previous solution:!! leave Note; if (nomilk) { if (nonote) { remove Note; What happens here?! Well, with human, probably nothing bad! With computer: no one ever buys milk! Too Much Milk Solution #2" How about labeled notes?! Now we can leave note before checking! Algorithm looks like this:!!!!!thread A!!Thread B! leave note A; leave note B; if (nonote B) { if (nonote A) { if (nomilk) { if (nomilk) { buy Milk; buy Milk; remove note A; remove note B; Does this work?! Lec 427! Lec 428! Page 7

Too Much Milk Solution #2" Possible for neither thread to buy milk!!!!!thread A!!Thread B! leave note A; leave note B; if (nonote A) { if (nomilk) { buy Milk; if (nonote B) { if (nomilk) { buy Milk; remove note B;! Really insidious:! Unlikely that this would happen, but will at worse possible time! Too Much Milk Solution #2: problem!" I m not getting milk, You re getting milk! This kind of lockup is called starvation!! Lec 429! Lec 430! Administrivia" Section assignments posted on Piazza! Most groups were assigned 1 st or 2 nd preference! Attend assigned sections THIS week! Nachos Project I begins tomorrow (Threads)! Start reading walkthrough and code NOW! Download Nachos tar file! Set up Java environment, Eclipse, version control! More details in sections! 5min Break" Sections will have weekly quizzes! New grade breakdown: 50% projects, 40% exams, 5% participation (lectures/sections/piazza), 5% quizzes! May have quizzes in lectures! Lec 431! Lec 432! Page 8

Too Much Milk Solution #3" Here is a possible two-note solution:!!!!thread A!!Thread B! leave note A; leave note B; while (note B) {\\X if (nonote A) {\\Y do nothing; if (nomilk) { if (nomilk) { remove note B; remove note A;! Does this work? Yes Both can guarantee that:! It is safe to buy, or! Other will buy, ok to quit! At X:! if no note B, safe for A to buy,! otherwise wait to find out what will happen! At Y:! if no note A, safe for B to buy! Otherwise, A is either buying or waiting for B to quit! Lec 433! Solution #3 discussion" Our solution protects a single Critical-Section piece of code for each thread:! if (nomilk) {! Solution #3 works, but it s really unsatisfactory! Really complex even for this simple an example!» Hard to convince yourself that this really works! A s code is different from B s what if lots of threads?!» Code would have to be slightly different for each thread! While A is waiting, it is consuming CPU time!» This is called busy-waiting! There s a better way! Have hardware provide better (higher-level) primitives than atomic load and store! Build even higher-level programming abstractions on this new hardware support! Lec 434! High-Level Picture" The abstraction of threads is good:! Maintains sequential execution model! Allows simple parallelism to overlap I/O and computation! Unfortunately, still too complicated to access state shared between threads! Consider too much milk example! Implementing a concurrent program with only loads and stores would be tricky and error-prone! We ll implement higher-level operations on top of atomic operations provided by hardware! Develop a synchronization toolbox! Explore some common programming paradigms! Too Much Milk: Solution #4" Suppose we have some sort of implementation of a lock (more in a moment)! LockAcquire() wait until lock is free, then grab! LockRelease() unlock, waking up anyone waiting! These must be atomic operations if two threads are waiting for the lock, only one succeeds to grab the lock! Then, our milk problem is easy:!! milklockacquire(); if (nomilk) milklockrelease(); Lec 435! Once again, section of code between Acquire() and Release() called a Critical Section! Lec 436! Page 9

How to Implement Lock?" Lock: prevents someone from accessing something! Lock before entering critical section (eg, before accessing shared data)! Unlock when leaving, after accessing shared data! Wait if locked!» Important idea: all synchronization involves waiting!» Should sleep if waiting for long time! Hardware lock instructions! Is this a good idea?! What about putting a task to sleep?!» How do handle interface between hardware and scheduler?! Complexity?!» Each feature makes hardware more complex and slower! Naïve use of Interrupt Enable/Disable" How can we build multi-instruction atomic operations?! Recall: dispatcher gets control in two ways!» Internal: Thread does something to relinquish the CPU!» External: Interrupts cause dispatcher to take CPU! On a uniprocessor, can avoid context-switching by:!» Avoiding internal events (although virtual memory tricky)!» Preventing external events by disabling interrupts! Consequently, naïve Implementation of locks:!!!lockacquire { disable Ints; LockRelease { enable Ints;! Lec 437! Lec 438! Naïve use of Interrupt Enable/Disable: Problems" Can t let user do this! Consider following:! LockAcquire(); While(TRUE) {; Real-Time system no guarantees on timing!! Critical Sections might be arbitrarily long! What happens with I/O or other important events?!! Reactor about to meltdown Help?! Better Implementation of Locks by Disabling Interrupts" Key idea: maintain a lock variable and impose mutual exclusion only during operations on that variable! int value = FREE; Acquire() { disable interrupts; if (value == BUSY) { put thread on wait queue; Go to sleep(); // Enable interrupts? else { value = BUSY; enable interrupts; Release() { disable interrupts; if (anyone on wait queue) { take thread off wait queue Put at front of ready queue else { value = FREE; enable interrupts; Lec 439! Lec 440! Page 10

New Lock Implementation: Discussion" Disable interrupts: avoid interrupting between checking and setting lock value! Otherwise two threads could think that they both have lock! Acquire() { disable interrupts; if (value == BUSY) { put thread on wait queue; Go to sleep(); // Enable interrupts? else { value = BUSY; enable interrupts; Critical Section! Note: unlike previous solution, critical section very short! User of lock can take as long as they like in their own critical section! Critical interrupts taken in time! Lec 441! Interrupt re-enable in going to sleep" What about re-enabling ints when going to sleep?! Acquire() { disable interrupts; if (value == BUSY) { Enable Position" put thread on wait queue; Enable Position" go to sleep(); Enable Position" else { value = BUSY; enable interrupts; Before putting thread on the wait queue?! Release can check the queue and not wake up thread! After putting the thread on the wait queue! Release puts the thread on the ready queue, but the thread still thinks it needs to go to sleep! Misses wakeup and still holds lock (deadlock!)! Want to put it after sleep() But, how?! Lec 442! How to Re-enable After Sleep()?" Since ints are disabled when you call sleep:! Responsibility of the next thread to re-enable ints! When the sleeping thread wakes up, returns to acquire and reenables interrupts! Thread A!Thread B! disable ints sleep sleep return enable ints context switch" context switch" sleep yield return enable ints disable disable int int sleep yield Summary" Introduced important concept: Atomic Operations! An operation that runs to completion or not at all! These are the primitives on which to construct various synchronization primitives!! Showed construction of Locks using interrupts! Using careful disabling of interrupts! Must be very careful not to waste/tie up machine resources!» Shouldn t disable interrupts for long! Key ideas: Use a separate lock variable, and use hardware mechanisms to protect modifications of that variable! Lec 443! Lec 444! Page 11