CS423: Operating Systems Design
CS 423 Operating System Design:
Sy Sync nchr hroniz nizatio ion
Tianyin Tianyin Xu Xu
* Thanks for Prof. Adam Bates for the slides.
CS 423 Operating System Design: Sy Sync nchr hroniz nizatio - - PowerPoint PPT Presentation
CS 423 Operating System Design: Sy Sync nchr hroniz nizatio ion Tianyin Tianyin Xu Xu * Thanks for Prof. Adam Bates for the slides. CS423: Operating Systems Design Please post the topic youd like me to chat about in the first 10
CS423: Operating Systems Design
* Thanks for Prof. Adam Bates for the slides.
CS423: Operating Systems Design
CS423: Operating Systems Design
CS423: Operating Systems Design
4
CS423: Operating Systems Design
5
CS423: Operating Systems Design
6
CS423: Operating Systems Design
7
CS423: Operating Systems Design
8
srsly tho — https://minimalistbaker.com/make-oat-milk/
CS423: Operating Systems Design
9
CS423: Operating Systems Design
10
CS423: Operating Systems Design 11
CS423: Operating Systems Design
12
CS423: Operating Systems Design
13
CS423: Operating Systems Design
14
CS423: Operating Systems Design
15
CS423: Operating Systems Design 16
CS423: Operating Systems Design
17
CS423: Operating Systems Design
18
CS423: Operating Systems Design
20
CS423: Operating Systems Design
21
CS423: Operating Systems Design
22
CS423: Operating Systems Design
23
Lock::acquire() { disableInterrupts(); if (value == BUSY) { waiting.add(myTCB); myTCB->state = WAITING; next = readyList.remove(); switch(myTCB, next); myTCB->state = RUNNING; } else { value = BUSY; } enableInterrupts(); } Lock::release() { disableInterrupts(); if (!waiting.Empty()) { next = waiting.remove(); next->state = READY; readyList.add(next); } else { value = FREE; } enableInterrupts(); }
CS423: Operating Systems Design
24
CS423: Operating Systems Design
25
methodThatWaits() { lock.acquire(); // Read/write shared state while (!testSharedState()) { cv.wait(&lock); } // Read/write shared state lock.release(); } methodThatSignals() { lock.acquire(); // Read/write shared state // If testSharedState is now true cv.signal(&lock); // Read/write shared state lock.release(); }
CS423: Operating Systems Design 26
get() { lock.acquire(); while (front == tail) { empty.wait(lock); } item = buf[front % MAX]; front++; full.signal(lock); lock.release(); return item; } put(item) { lock.acquire(); while ((tail – front) == MAX) { full.wait(lock); } buf[tail % MAX] = item; tail++; empty.signal(lock); lock.release(); }
Initially: front = tail = 0; MAX is buffer capacity empty/full are condition variables
CS423: Operating Systems Design
27
CS423: Operating Systems Design
28 methodThatWaits() { lock.acquire(); // Pre-condition: State is consistent // Read/write shared state while (!testSharedState()) { cv.wait(&lock); } // WARNING: shared state may // have changed! But // testSharedState is TRUE // and pre-condition is true // Read/write shared state lock.release(); } methodThatSignals() { lock.acquire(); // Pre-condition: State is consistent // Read/write shared state // If testSharedState is now true cv.signal(&lock); // NO WARNING: signal keeps lock // Read/write shared state lock.release(); }
CS423: Operating Systems Design
29
CS423: Operating Systems Design
30
immediately
while (needToWait()) { condition.Wait(lock); }
CS423: Operating Systems Design
31
CS423: Operating Systems Design
32
get() { lock.acquire(); if (front == tail) { empty.wait(lock); } item = buf[front % MAX]; front++; full.signal(lock); lock.release(); return item; } put(item) { lock.acquire(); if ((tail – front) == MAX) { full.wait(lock); } buf[last % MAX] = item; last++; empty.signal(lock); // CAREFUL: someone else ran lock.release(); }
Initially: front = tail = 0; MAX is buffer capacity empty/full are condition variables
CS423: Operating Systems Design
33
CS423: Operating Systems Design
35
concurrently
CS423: Operating Systems Design
36