week3_frid - CSCC 69H3 Operating Systems Winter 2010...

Info iconThis preview shows pages 1–12. Sign up to view the full content.

View Full Document Right Arrow Icon
CSCC 69H3 Operating Systems Winter 2010 Professor Bianca Schroeder U of T
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Higher-level Abstractions for CS’s Locks Very primitive, minimal semantics Operations: acquire(lock), release(lock) Semaphores Basic, easy to understand, hard to program with Monitors High-level, ideally has language support (Java) Messages Simple model for communication & synchronization Direct application to distributed systems
Background image of page 2
Quick recap from last time What is a monitor?
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
What is a monitor? an abstract data type: with restriction that only one process at a time can be active within the monitor Local data accessed only by monitor’s procedures Process enters monitor by invoking 1 of its procedures Other processes that attempt to enter monitor are blocked C ondition variables: wait (suspend the invoking process) signal (resume exactly one suspended process) Local data Condition Vars Procedure 1 Procedure N Initialization Code Enter queue Exit Condition 1 Condition m
Background image of page 4
Remember the readers/writers problem from last lecture? Let’s try and solve it with monitors.
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
The readers/writers problem Multiple readers or … One writer Shared object • An object is shared among several threads • Some only read the object, others only write it • We can allow multiple concurrent readers • But only one writer How can we implement this with monitors ?
Background image of page 6
Monitor for readers/writers Start_read() End_write() Initialization Code Enter queue Exit End_read() Start_write() int readcount bool w_busy Local data condition OKtoread condition OKtowrite OKtoread OKtowrite Condition Vars while(w_busy|| readcount>0) OKtowrite.wait(); busy = 1; while(w_busy) OKtoread.wait(); readcount++; OKtoread.signal(); w_busy = 0; if (readers waiting) Oktoread_signal() else Oktowrite_signal(); readcount--; if (readcount==0) OKtowrite.signal();
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Next … transactions & deadlock What is a transaction? A collection of operations that performs a single logical function The collection of operations appear as a single atomic operation
Background image of page 8
What is atomicity? Recall ATM banking example: Concurrent deposit/withdrawal operation Need to protect shared account balance What about transferring funds between accounts? Withdraw funds from account A Deposit funds into account B Should appear as a single atomic operation Another process reading the account balances should see either both updates, or none Either both operations complete, or neither does
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Why would atomicity fail? Suppose fund transfer is implemented by our known withdraw and deposit functions using locks. Withdraw(acct, amt) { acquire(lock); balance = get_balance(acct); balance = balance - amt; put_balance(acct,balance); release(lock); return balance; } Deposit(acct, amt) { acquire(lock); balance = get_balance(acct); balance = balance + amt; put_balance(acct,balance); release(lock); return balance; } Transfer (acctA, acctB, amt) { Withdraw (acctA,amt); Deposit (acctB,amt; } What can go wrong?
Background image of page 10
Definitions for Transactions Defn: Transaction
Background image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 12
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 43

week3_frid - CSCC 69H3 Operating Systems Winter 2010...

This preview shows document pages 1 - 12. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online