Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
X
xv6-public
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
问题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
银宸时代
OS Lab Group
奖励实验
xv6-public
提交
beed8e04
提交
beed8e04
3月 01, 2012
创建
作者:
Nickolai Zeldovich
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
pthread-like thing
上级
c132eade
隐藏空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
94 行增加
和
15 行删除
+94
-15
mapbench.cc
bin/mapbench.cc
+6
-6
maptest.cc
bin/maptest.cc
+5
-4
thrtest.cc
bin/thrtest.cc
+4
-4
pthread.h
include/pthread.h
+14
-0
user.h
include/user.h
+1
-0
Makefrag
lib/Makefrag
+2
-1
threads.cc
lib/threads.cc
+62
-0
没有找到文件。
bin/mapbench.cc
浏览文件 @
beed8e04
...
...
@@ -4,12 +4,13 @@
#include "mtrace.h"
#include "amd64.h"
#include "uspinlock.h"
#include "pthread.h"
enum
{
readaccess
=
0
};
enum
{
verbose
=
0
};
enum
{
npg
=
1
};
void
void
*
thr
(
void
*
arg
)
{
u64
tid
=
(
u64
)
arg
;
...
...
@@ -34,6 +35,7 @@ thr(void *arg)
exit
();
}
}
return
0
;
}
int
...
...
@@ -50,11 +52,9 @@ main(int ac, char **av)
// fprintf(1, "mapbench[%d]: start esp %x, nthread=%d\n", getpid(), rrsp(), nthread);
for
(
int
i
=
0
;
i
<
nthread
;
i
++
)
{
sbrk
(
8192
);
void
*
tstack
=
sbrk
(
0
);
// fprintf(1, "tstack %lx\n", tstack);
int
tid
=
forkt
(
tstack
,
(
void
*
)
thr
,
(
void
*
)(
u64
)
i
);
for
(
u64
i
=
0
;
i
<
nthread
;
i
++
)
{
pthread_t
tid
;
pthread_create
(
&
tid
,
0
,
thr
,
(
void
*
)
i
);
if
(
0
)
fprintf
(
1
,
"mapbench[%d]: child %d
\n
"
,
getpid
(),
tid
);
}
...
...
bin/maptest.cc
浏览文件 @
beed8e04
...
...
@@ -4,6 +4,7 @@
#include "mtrace.h"
#include "amd64.h"
#include "uspinlock.h"
#include "pthread.h"
static
volatile
char
*
p
;
static
struct
uspinlock
l
;
...
...
@@ -17,8 +18,8 @@ spin(void)
;
}
void
thr
(
void
)
void
*
thr
(
void
*
)
{
for
(;;)
{
acquire
(
&
l
);
...
...
@@ -54,8 +55,8 @@ main(void)
exit
();
}
sbrk
(
4096
)
;
forkt
(
sbrk
(
0
),
(
void
*
)
thr
,
0
);
pthread_t
tid
;
pthread_create
(
&
tid
,
0
,
thr
,
0
);
acquire
(
&
l
);
state
=
1
;
...
...
bin/thrtest.cc
浏览文件 @
beed8e04
...
...
@@ -4,12 +4,13 @@
#include "mtrace.h"
#include "amd64.h"
#include "uspinlock.h"
#include "pthread.h"
static
struct
uspinlock
l
;
static
volatile
int
tcount
;
enum
{
nthread
=
8
};
void
void
*
thr
(
void
*
arg
)
{
acquire
(
&
l
);
...
...
@@ -26,9 +27,8 @@ main(void)
fprintf
(
1
,
"thrtest[%d]: start esp %x
\n
"
,
getpid
(),
rrsp
());
for
(
int
i
=
0
;
i
<
nthread
;
i
++
)
{
sbrk
(
8192
);
void
*
tstack
=
sbrk
(
0
);
int
tid
=
forkt
(
tstack
,
(
void
*
)
thr
,
(
void
*
)(
u64
)(
0xc0ffee00
|
i
));
pthread_t
tid
;
pthread_create
(
&
tid
,
0
,
&
thr
,
(
void
*
)
(
0xc0ffee00ULL
|
i
));
fprintf
(
1
,
"thrtest[%d]: child %d
\n
"
,
getpid
(),
tid
);
}
...
...
include/pthread.h
0 → 100644
浏览文件 @
beed8e04
/*
* Our minimal version of pthreads
*/
typedef
int
pthread_t
;
typedef
int
pthread_attr_t
;
typedef
int
pthread_key_t
;
int
pthread_create
(
pthread_t
*
tid
,
const
pthread_attr_t
*
attr
,
void
*
(
*
start
)(
void
*
),
void
*
arg
);
pthread_t
pthread_self
(
void
);
int
pthread_key_create
(
pthread_key_t
*
key
,
void
(
*
destructor
)(
void
*
));
void
*
pthread_getspecific
(
pthread_key_t
key
);
int
pthread_setspecific
(
pthread_key_t
key
,
void
*
value
);
include/user.h
浏览文件 @
beed8e04
...
...
@@ -50,6 +50,7 @@ int atoi(const char*);
// uthread.S
int
forkt
(
void
*
sp
,
void
*
pc
,
void
*
arg
);
void
forkt_setup
(
void
);
// printf.c
void
printf
(
const
char
*
,
...);
...
...
lib/Makefrag
浏览文件 @
beed8e04
ULIB = ulib.o usys.o printf.o umalloc.o uthread.o fmt.o stream.o ipc.o
ULIB = ulib.o usys.o printf.o umalloc.o uthread.o fmt.o stream.o ipc.o \
threads.o
ULIB := $(addprefix $(O)/lib/, $(ULIB))
.PRECIOUS: $(O)/lib/%.o
...
...
lib/threads.cc
0 → 100644
浏览文件 @
beed8e04
#include "types.h"
#include "pthread.h"
#include "user.h"
#include "atomic.hh"
enum
{
stack_size
=
8192
};
static
std
::
atomic
<
int
>
nextkey
;
struct
tlsdata
{
void
*
buf
[
128
];
};
void
forkt_setup
()
{
printf
(
"forkt_setup: pid %d
\n
"
,
getpid
());
tlsdata
*
t
=
(
tlsdata
*
)
sbrk
(
sizeof
(
*
t
));
setfs
((
u64
)
t
);
}
int
pthread_create
(
pthread_t
*
tid
,
const
pthread_attr_t
*
attr
,
void
*
(
*
start
)(
void
*
),
void
*
arg
)
{
char
*
base
=
(
char
*
)
sbrk
(
stack_size
);
int
t
=
forkt
(
base
+
stack_size
,
(
void
*
)
start
,
arg
);
if
(
t
<
0
)
return
t
;
*
tid
=
t
;
return
0
;
}
pthread_t
pthread_self
()
{
return
getpid
();
}
int
pthread_key_create
(
pthread_key_t
*
key
,
void
(
*
destructor
)(
void
*
))
{
// Ignore the destructor for now.
*
key
=
nextkey
++
;
return
0
;
}
void
*
pthread_getspecific
(
pthread_key_t
key
)
{
u64
v
;
__asm
volatile
(
"movq %%fs:(%1), %0"
:
"=r"
(
v
)
:
"r"
(
key
*
8
));
return
(
void
*
)
v
;
}
int
pthread_setspecific
(
pthread_key_t
key
,
void
*
value
)
{
__asm
volatile
(
"movq %0, %%fs:(%1)"
:
:
"r"
(
value
),
"r"
(
key
*
8
));
return
0
;
}
编写
预览
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论