提交 c4cda662 创建 作者: Nickolai Zeldovich's avatar Nickolai Zeldovich

threads work (or at least thrtest)

上级 71f48f08
......@@ -7,7 +7,7 @@
static struct uspinlock l;
static volatile uint tcount;
enum { nthread = 1 };
enum { nthread = 4 };
void
thr(uint arg)
......@@ -23,7 +23,7 @@ int
main(void)
{
acquire(&l);
printf(1, "thrtest[%d]: start\n", getpid());
printf(1, "thrtest[%d]: start esp %x\n", getpid(), resp());
for(uint i = 0; i < nthread; i++) {
sbrk(4096);
......@@ -31,16 +31,23 @@ main(void)
tstack[-1] = 0xc0ffee00 | i;
int tid = forkt(&tstack[-2], thr);
printf(1, "thrtest[%d]: child %d esp %x\n", getpid(), tid, resp());
printf(1, "thrtest[%d]: child %d\n", getpid(), tid);
}
for(;;){
uint lastc = tcount;
printf(1, "thrtest[%d]: tcount=%d\n", getpid(), lastc);
release(&l);
if(lastc==nthread)
break;
while(tcount==lastc)
__asm __volatile("");
acquire(&l);
}
release(&l);
exit();
printf(1, "thrtest[%d]: done\n", getpid());
do{
printf(1, "thrtest[%d]: %d\n", getpid(), tcount);
for(uint i = 0; i < 100000; i++)
;
//sleep(1);
}while(tcount < nthread);
for(uint i = 0; i < nthread; i++)
wait();
exit();
}
......@@ -2,7 +2,7 @@
#include "x86.h"
struct uspinlock {
uint locked; // Is the lock held?
volatile uint locked; // Is the lock held?
};
static void inline __attribute__((always_inline))
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论