This preview shows pages 1–3. Sign up to view the full content.
1
UVa CS205 Engineering Software 2008
Locking and Deadlock
UVa CS205 Engineering Software 2008
Scheduling Meetings
Alice wants to schedule a meeting with Bob and
Colleen
Bob
Alice
Colleen
“When can
you meet
Friday?”
“When can
you meet
Friday?”
“11am or 3pm”
“9am or 11am”
“Let’s meet
at 11am”
“Let’s meet
at 11am”
Reserves 11am
for meeting
Reserves 11am
for meeting
Picks
meeting time
UVa CS205 Engineering Software 2008
Partial Ordering of Events
±
Sequential programs give us a
total ordering
of events: everything happens in a
determined order
±
Concurrency gives us a
partial ordering
of
events: we know some things happen before
other things, but not total order
Alice asks to schedule meeting before Bob replies
Alice asks to schedule meeting before Colleen replies
Bob and Colleen both reply before Alice picks meeting time
Alice picks meeting time before Bob reserves time on calendar
UVa CS205 Engineering Software 2008
Race Condition
Bob
Alice
Colleen
“When can
you meet
Friday?”
“When can
you meet
Friday?”
“9, 11am or 3pm”
“9am or 11am”
“Let’s meet
at 11am”
“Let’s meet
at 11am”
Picks
meeting time
Doug
“When can
you meet
Friday?”
“9, 11am or 3pm”
“Let’s meet
at 11am”
Reserves 11am
for Doug
“I’m busy
then…”
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document2
UVa CS205 Engineering Software 2008
Preventing Race Conditions
±
Use locks to impose ordering constraints
²
Be sure your solution (algorithm) is best for
concurrent execution – the best sequential
algorithm often does not become the best
concurrent one.
²
There is a
nondeterministic
solution to
scheduling that doesn’t require locks!
±
After responding to Alice, Bob reserves all the
times in his response until he hears back
(and then frees the other times)
UVa CS205 Engineering Software 2008
Locking
Bob
Alice
Colleen
“When can
you meet
Friday?”
“When can
you meet
Friday?”
“9, 11am or 3pm”
“9am or 11am”
“Let’s meet
at 11am”
“Let’s meet
at 11am”
Picks
meeting time
Doug
“When can
you meet
Friday?”
“3pm”
“Let’s meet
at 3”
Locks calendar
UVa CS205 Engineering Software 2008
This is the end of the preview. Sign up
to
access the rest of the document.
 Spring '08
 Humphreys,G

Click to edit the document details