Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
X
xv6-public
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
问题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
银宸时代
OS Lab Group
奖励实验
xv6-public
提交
020c8e23
提交
020c8e23
8月 04, 2014
创建
作者:
Robert Morris
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
use acquire/release to force order for pid=np->pid;np->state=RUNNING
for bug reported by symingz@gmail.com and cs1100254@cse.iitd.ernet.in
上级
86188d9d
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
19 行增加
和
11 行删除
+19
-11
TRICKS
TRICKS
+11
-7
proc.c
proc.c
+7
-3
proc.h
proc.h
+1
-1
没有找到文件。
TRICKS
浏览文件 @
020c8e23
...
...
@@ -116,21 +116,25 @@ processors will need it.
---
The code in fork needs to read np->pid before
setting np->state to RUNNABLE.
setting np->state to RUNNABLE. The following
is not a correct way to do this:
int
fork(void)
{
...
pid = np->pid;
np->state = RUNNABLE;
return
pid;
return
np->pid; // oops
}
After setting np->state to RUNNABLE, some other CPU
might run the process, it might exit, and then it might
get reused for a different process (with a new pid), all
before the return statement. So it's not safe to just do
"return np->pid;".
This works because proc.h marks the pid as volatile.
before the return statement. So it's not safe to just
"return np->pid". Even saving a copy of np->pid before
setting np->state isn't safe, since the compiler is
allowed to re-order statements.
The real code saves a copy of np->pid, then acquires a lock
around the write to np->state. The acquire() prevents the
compiler from re-ordering.
proc.c
浏览文件 @
020c8e23
...
...
@@ -154,9 +154,15 @@ fork(void)
np
->
ofile
[
i
]
=
filedup
(
proc
->
ofile
[
i
]);
np
->
cwd
=
idup
(
proc
->
cwd
);
safestrcpy
(
np
->
name
,
proc
->
name
,
sizeof
(
proc
->
name
));
pid
=
np
->
pid
;
// lock to force the compiler to emit the np->state write last.
acquire
(
&
ptable
.
lock
);
np
->
state
=
RUNNABLE
;
safestrcpy
(
np
->
name
,
proc
->
name
,
sizeof
(
proc
->
name
));
release
(
&
ptable
.
lock
);
return
pid
;
}
...
...
@@ -455,5 +461,3 @@ procdump(void)
cprintf
(
"
\n
"
);
}
}
proc.h
浏览文件 @
020c8e23
...
...
@@ -57,7 +57,7 @@ struct proc {
pde_t
*
pgdir
;
// Page table
char
*
kstack
;
// Bottom of kernel stack for this process
enum
procstate
state
;
// Process state
volatile
int
pid
;
// Process ID
int
pid
;
// Process ID
struct
proc
*
parent
;
// Parent process
struct
trapframe
*
tf
;
// Trap frame for current syscall
struct
context
*
context
;
// swtch() here to run process
...
...
编写
预览
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论