Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
X
xv6-public
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
问题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
银宸时代
OS Lab Group
奖励实验
xv6-public
提交
e1f627d7
提交
e1f627d7
5月 10, 2011
创建
作者:
Nickolai Zeldovich
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
forgot to git add
上级
989c0584
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
89 行增加
和
0 行删除
+89
-0
thrtest.c
thrtest.c
+46
-0
uspinlock.h
uspinlock.h
+20
-0
uthread.S
uthread.S
+23
-0
没有找到文件。
thrtest.c
0 → 100644
浏览文件 @
e1f627d7
#include "types.h"
#include "stat.h"
#include "user.h"
#include "xv6-mtrace.h"
#include "x86.h"
#include "uspinlock.h"
static
struct
uspinlock
l
;
static
volatile
uint
tcount
;
enum
{
nthread
=
1
};
void
thr
(
uint
arg
)
{
acquire
(
&
l
);
printf
(
1
,
"thrtest[%d]: arg 0x%x esp %x
\n
"
,
getpid
(),
arg
,
resp
());
tcount
++
;
release
(
&
l
);
exit
();
}
int
main
(
void
)
{
acquire
(
&
l
);
printf
(
1
,
"thrtest[%d]: start
\n
"
,
getpid
());
for
(
uint
i
=
0
;
i
<
nthread
;
i
++
)
{
sbrk
(
4096
);
uint
*
tstack
=
(
uint
*
)
sbrk
(
0
);
tstack
[
-
1
]
=
0xc0ffee00
|
i
;
int
tid
=
forkt
(
&
tstack
[
-
2
],
thr
);
printf
(
1
,
"thrtest[%d]: child %d esp %x
\n
"
,
getpid
(),
tid
,
resp
());
}
release
(
&
l
);
exit
();
do
{
printf
(
1
,
"thrtest[%d]: %d
\n
"
,
getpid
(),
tcount
);
for
(
uint
i
=
0
;
i
<
100000
;
i
++
)
;
//sleep(1);
}
while
(
tcount
<
nthread
);
}
uspinlock.h
0 → 100644
浏览文件 @
e1f627d7
#pragma once
#include "x86.h"
struct
uspinlock
{
uint
locked
;
// Is the lock held?
};
static
void
inline
__attribute__
((
always_inline
))
acquire
(
struct
uspinlock
*
lk
)
{
while
(
xchg
(
&
lk
->
locked
,
1
)
!=
0
)
;
}
static
void
inline
__attribute__
((
always_inline
))
release
(
struct
uspinlock
*
lk
)
{
xchg
(
&
lk
->
locked
,
0
);
}
uthread.S
0 → 100644
浏览文件 @
e1f627d7
#include "syscall.h"
#include "traps.h"
.globl forkt
forkt:
movl 4(%esp), %ecx ## new stack ptr
movl 8(%esp), %edx ## function ptr
pushl $1 ## flag for sys_fork
pushl $0 ## return address (dummy)
movl $SYS_fork, %eax
int $T_SYSCALL
addl $8, %esp
cmpl $0, %eax
jne 1f
movl %eax, %esp
jmp *%ecx
1:
ret
编写
预览
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论