Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
X
xv6-public
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
问题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
银宸时代
OS Lab Group
奖励实验
xv6-public
提交
949352af
提交
949352af
10月 12, 2007
创建
作者:
rsc
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Model verifying that wakeup really
can be called after release without causing deadlock.
上级
943fd378
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
150 行增加
和
0 行删除
+150
-0
sleep1.p
sleep1.p
+134
-0
spinp
spinp
+16
-0
没有找到文件。
sleep1.p
0 → 100644
浏览文件 @
949352af
/*
This file defines a Promela model for xv6's
acquire, release, sleep, and wakeup, along with
a model of a simple producer/consumer queue.
To run:
spinp sleep1.p
(You may need to install Spin, available at http://spinroot.com/.)
After a successful run spin prints something like:
unreached in proctype consumer
(0 of 37 states)
unreached in proctype producer
(0 of 23 states)
After an unsuccessful run, the spinp script prints
an execution trace that causes a deadlock.
The safe body of producer reads:
acquire(lk);
x = value; value = x + 1; x = 0;
wakeup(0);
release(lk);
i = i + 1;
If this is changed to:
x = value; value = x + 1; x = 0;
acquire(lk);
wakeup(0);
release(lk);
i = i + 1;
then a deadlock can happen, because the non-atomic
increment of value conflicts with the non-atomic
decrement in consumer, causing value to have a bad value.
Try this.
If it is changed to:
acquire(lk);
x = value; value = x + 1; x = 0;
release(lk);
wakeup(0);
i = i + 1;
then nothing bad happens: it is okay to wakeup after release
instead of before, although it seems morally wrong.
*/
#define ITER 4
#define N 2
bit
lk
;
byte
value
;
bit
sleeping
[
N
];
inline
acquire
(
x
)
{
atomic
{
x
==
0
;
x
=
1
}
}
inline
release
(
x
)
{
assert
x
==
1
;
x
=
0
}
inline
sleep
(
cond
,
lk
)
{
assert
!
sleeping
[
_pid
];
if
::
cond
->
skip
::
else
->
atomic
{
release
(
lk
);
sleeping
[
_pid
]
=
1
};
sleeping
[
_pid
]
==
0
;
acquire
(
lk
)
fi
}
inline
wakeup
()
{
w
=
0
;
do
::
w
<
N
->
sleeping
[
w
]
=
0
;
w
=
w
+
1
::
else
->
break
od
}
active
[
N
]
proctype
consumer
()
{
byte
i
,
x
;
i
=
0
;
do
::
i
<
ITER
->
acquire
(
lk
);
sleep
(
value
>
0
,
lk
);
x
=
value
;
value
=
x
-
1
;
x
=
0
;
release
(
lk
);
i
=
i
+
1
;
::
else
->
break
od
;
i
=
0
;
skip
}
active
[
N
]
proctype
producer
()
{
byte
i
,
x
,
w
;
i
=
0
;
do
::
i
<
ITER
->
acquire
(
lk
);
x
=
value
;
value
=
x
+
1
;
x
=
0
;
release
(
lk
);
wakeup
();
i
=
i
+
1
;
::
else
->
break
od
;
i
=
0
;
skip
}
spinp
0 → 100755
浏览文件 @
949352af
#!/bin/sh
if
[
$#
!=
1
]
||
[
!
-f
"
$1
"
]
;
then
echo
'usage: spinp file.p'
1>&2
exit
1
fi
rm
-f
$1
.trail
spin
-a
$1
||
exit
1
cc
-DSAFETY
-DREACH
-DMEMLIM
=
500
-o
pan pan.c
pan
-i
rm
pan.
*
pan
if
[
-f
$1
.trail
]
;
then
spin
-t
-p
$1
fi
编写
预览
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论