int x co < x = . . . > < x = . . . > || < x = . . . > oc |
int x peterson cs co cs.enter1() x = . . . x = . . . cs.exit1() || cs.enter2() x = . . . cs.exit2() oc |
int x, y co < x = no y > < y = no x > || < y = no x > < x = no y > oc |
int x, y bakery xcs(2), ycs(2) co xcs.enter(1) x = no y xcs.exit(1) ycs.enter(1) y = no x ycs.exit(1) || ycs.enter(2) y = no x ycs.exit(2) xcs.enter(2) x = no y xcs.exit(2) oc |
cs.entry(i) // whatever if B cs.exit(i)
class stanley const critical_section & cs const unsigned tid stanley(critical_section & cs unsigned tid) : cs(cs), tid(tid) cs.enter(tid) ~stanley() cs.exit(tid) void f(critical_section & cs) { const stanley s(cs, tid) // whatever }
class database const unsigned n Bakery cs(n) vector db void write(unsigned tid, data d) cs.enter(tid) db = d cs.exit(tid)
< await B ; S >
B
is true, then do S
, all atomically.
cs-enter() while (not B) skip S cs-exit()
B
can never change.
B
occur in the same critical section.
while (not B) skip cs-enter() S cs-exit()
B
can be interfered with.
B
is false, step out and let another computation in.
cs-enter() while (not B) cs-exit() cs-enter() S cs-exit()
cs-enter() while (not B) cs-exit() random_delay() cs-enter() S cs-exit()
This page last modified on 1 July 2003.