提交 97cebac1 编写于 作者: Y Yifan Wu

update peterson tests

上级 c31c27ab
......@@ -30,7 +30,8 @@ unsafe fn critical_section(t: &mut usize) {
unsafe fn lock(id: usize) {
FLAG[id] = true;
TURN = 1 - id;
let j = 1 - id;
TURN = j;
// Tell the compiler not to reorder memory operations
// across this fence.
compiler_fence(Ordering::SeqCst);
......@@ -38,7 +39,7 @@ unsafe fn lock(id: usize) {
// Otherwise the compiler will assume that they will never
// be changed on this thread. Thus, they will be accessed
// only once!
while vload!(&FLAG[1 - id]) && vload!(&TURN) == 1 - id {}
while vload!(&FLAG[j]) && vload!(&TURN) == j {}
}
unsafe fn unlock(id: usize) {
......
......@@ -30,11 +30,12 @@ unsafe fn critical_section(t: &mut usize) {
unsafe fn lock(id: usize) {
FLAG[id] = true;
TURN = 1 - id;
let j = 1 - id;
TURN = j;
// Tell the compiler not to reorder memory operations
// across this fence.
compiler_fence(Ordering::SeqCst);
while FLAG[1 - id] && TURN == 1 - id {
while FLAG[j] && TURN == j {
yield_();
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册