9/29/10
Lec 9.2
Wait if necessary
Signal when change something so any waiting threads
can proceed
unlock
9/29/10
Lec 9.3
Lec 9.4
9/29/10
Is it OK to miss deadlines?
Lec 9.5
Big Projects
What is a big project?
9/29/10
Lec 9.6
Task
9/29/10
Lec 9.7
Communication
More people mean more communication
Miscommunication is common
9/29/10
Lec 9.8
Coordination
More people no one can make all meetings!
9/29/10
Lec 9.9
What to document?
Standardize!
9/29/10
Lec 9.10
Meeting notes
Document all decisions
You can often cut & paste for the design documents
Organizational Chart
Who is responsible for what task?
9/29/10
Lec 9.11
Lec 9.12
Test Continuously
Integration tests all the time, not at 11pm
on due date!
Write dummy stubs with simple functionality
Testing types:
9/29/10
Lec 9.13
Administrivia
Project 1 Code (and final design document)
Due Tuesday 10/5 (next Tuesday!), Document Wednesday
Project 2 starts after you are done with Project 1
Autograder issues
Autograder not intended to run frequently at beginning
Assume running every 4 hours or so at beginning of week
Lec 9.14
Proc A
Proc B
Calls setjmp
Proc C
lock.acquire
Stack growth
int Rtn() {
lock.acquire();
if (exception) {
lock.release();
return errReturnCode;
}
lock.release();
return OK;
}
Proc D
Proc E
Calls longjmp
9/29/10
Lec 9.15
DoFoo();
lock.release();
}
void DoFoo() {
Lec 9.16
DoFoo();
} catch () {
//
lock.release(); //
throw;
//
}
lock.release();
}
void DoFoo() {
if (exception) throw
catch exception
release lock
re-throw the exception
errException;
9/29/10
Lec 9.17
class Account {
private int balance;
// object constructor
public Account (int initialBalance) {
balance = initialBalance;
}
public synchronized int getBalance() {
return balance;
}
public synchronized void deposit(int amount) {
balance += amount;
}
}
Lec 9.18
DoFoo();
}
void DoFoo() {
throw errException;
}
9/29/10
Lec 9.19
void notify();
// wakes up oldest waiter
void notifyAll(); // like broadcast, wakes everyone
9/29/10
Lec 9.20
9/29/10
Lec 9.21
Resources
Resources passive entities needed by threads to do their
work
CPU time, disk space, memory
Lec 9.22
Starvation vs Deadlock
Starvation vs. Deadlock
Owned
By
Thread
A
Res 2
Res 1
Wait
For
Wait
For
Thread
B
Owned
By
Lec 9.23
Thread B
y.P();
x.P();
x.V();
y.V();
9/29/10
Lec 9.24
Starvation is possible
9/29/10
Lec 9.25
d
we
lo le
al u
is R
D By
9/29/10
Lec 9.26
9/29/10
Lec 9.27
No preemption
Circular wait
9/29/10
Lec 9.28
Resource-Allocation Graph
Symbols
System Model
A set of Threads T1, T2, . . ., Tn
Resource types R1, R2, . . ., Rm
T1
T2
R1
R2
Resource-Allocation Graph:
V is partitioned into two types:
T = {T1, T2, , Tn}, the set threads in the system.
R = {R1, R2, , Rm}, the set of resource types in system
Lec 9.29
Recall:
R1
T1
R2
T2
R3
R1
T3
R4
Simple Resource
Allocation Graph
9/29/10
T1
R2
T2
R3
R1
T3
R4
Allocation Graph
With Deadlock
Kubiatowicz CS162 UCB Fall 2010
T1
T2
T3
R2
T4
Allocation Graph
With Cycle, but
No Deadlock
Lec 9.30
9/29/10
Lec 9.31
R1
T1
9/29/10
T2
T3
R2
T4
Lec 9.32
Lec 9.33
Summary
Suggestions for dealing with Project Partners
No preemption
Circular wait
9/29/10
Lec 9.34
Summary (2)
Techniques for addressing Deadlock
Deadlock detection
9/29/10
Lec 9.35