Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
X
xv6-public
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
问题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
银宸时代
OS Lab Group
奖励实验
xv6-public
提交
118bc008
提交
118bc008
3月 01, 2012
创建
作者:
Nickolai Zeldovich
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fold thrtest into usertests
上级
2c2c24be
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
46 行增加
和
61 行删除
+46
-61
Makefrag
bin/Makefrag
+0
-1
thrtest.cc
bin/thrtest.cc
+0
-60
usertests.cc
bin/usertests.cc
+46
-0
没有找到文件。
bin/Makefrag
浏览文件 @
118bc008
...
...
@@ -11,7 +11,6 @@ UPROGS= \
mapbench \
maptest \
sh \
thrtest \
halt \
time \
sleep \
...
...
bin/thrtest.cc
deleted
100644 → 0
浏览文件 @
2c2c24be
#include "types.h"
#include "stat.h"
#include "user.h"
#include "mtrace.h"
#include "amd64.h"
#include "uspinlock.h"
#include "pthread.h"
static
struct
uspinlock
l
;
static
volatile
int
tcount
;
static
pthread_key_t
tkey
;
static
pthread_barrier_t
bar
;
enum
{
nthread
=
8
};
void
*
thr
(
void
*
arg
)
{
pthread_setspecific
(
tkey
,
arg
);
pthread_barrier_wait
(
&
bar
);
acquire
(
&
l
);
printf
(
"thrtest[%d]: arg 0x%lx rsp %lx spec %p
\n
"
,
getpid
(),
arg
,
rrsp
(),
pthread_getspecific
(
tkey
));
tcount
++
;
release
(
&
l
);
exit
();
}
int
main
(
void
)
{
acquire
(
&
l
);
fprintf
(
1
,
"thrtest[%d]: start esp %x
\n
"
,
getpid
(),
rrsp
());
pthread_key_create
(
&
tkey
,
0
);
pthread_barrier_init
(
&
bar
,
0
,
nthread
);
for
(
int
i
=
0
;
i
<
nthread
;
i
++
)
{
pthread_t
tid
;
pthread_create
(
&
tid
,
0
,
&
thr
,
(
void
*
)
(
0xc0ffee00ULL
|
i
));
fprintf
(
1
,
"thrtest[%d]: child %d
\n
"
,
getpid
(),
tid
);
}
for
(;;){
int
lastc
=
tcount
;
fprintf
(
1
,
"thrtest[%d]: tcount=%d
\n
"
,
getpid
(),
lastc
);
release
(
&
l
);
if
(
lastc
==
nthread
)
break
;
while
(
tcount
==
lastc
)
__asm
__volatile
(
""
);
acquire
(
&
l
);
}
release
(
&
l
);
fprintf
(
1
,
"thrtest[%d]: done
\n
"
,
getpid
());
for
(
int
i
=
0
;
i
<
nthread
;
i
++
)
wait
();
exit
();
}
bin/usertests.cc
浏览文件 @
118bc008
...
...
@@ -5,6 +5,7 @@
#include "fcntl.h"
#include "syscall.h"
#include "traps.h"
#include "pthread.h"
char
buf
[
2048
];
char
name
[
3
];
...
...
@@ -1600,6 +1601,7 @@ preads(void)
void
tls_test
(
void
)
{
printf
(
"tls_test
\n
"
);
u64
buf
[
128
];
for
(
int
i
=
0
;
i
<
sizeof
(
buf
)
/
sizeof
(
buf
[
0
]);
i
++
)
...
...
@@ -1626,6 +1628,49 @@ tls_test(void)
fprintf
(
1
,
"tls_test ok
\n
"
);
}
static
pthread_key_t
tkey
;
static
pthread_barrier_t
bar0
,
bar1
;
enum
{
nthread
=
8
};
static
void
*
thr
(
void
*
arg
)
{
pthread_setspecific
(
tkey
,
arg
);
pthread_barrier_wait
(
&
bar0
);
u64
x
=
(
u64
)
arg
;
if
((
x
>>
8
)
!=
0xc0ffee
)
fprintf
(
2
,
"thr: x 0x%lx
\n
"
,
x
);
if
(
arg
!=
pthread_getspecific
(
tkey
))
fprintf
(
2
,
"thr: arg %p getspec %p
\n
"
,
arg
,
pthread_getspecific
(
tkey
));
pthread_barrier_wait
(
&
bar1
);
return
0
;
}
void
thrtest
(
void
)
{
printf
(
"thrtest
\n
"
);
pthread_key_create
(
&
tkey
,
0
);
pthread_barrier_init
(
&
bar0
,
0
,
nthread
);
pthread_barrier_init
(
&
bar1
,
0
,
nthread
+
1
);
for
(
int
i
=
0
;
i
<
nthread
;
i
++
)
{
pthread_t
tid
;
pthread_create
(
&
tid
,
0
,
&
thr
,
(
void
*
)
(
0xc0ffee00ULL
|
i
));
}
pthread_barrier_wait
(
&
bar1
);
for
(
int
i
=
0
;
i
<
nthread
;
i
++
)
wait
();
printf
(
"thrtest ok
\n
"
);
}
int
main
(
int
argc
,
char
*
argv
[])
{
...
...
@@ -1674,6 +1719,7 @@ main(int argc, char *argv[])
exectest
();
tls_test
();
thrtest
();
exit
();
}
编写
预览
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论