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

forgot to git add

上级 989c0584
#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);
}
#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);
}
#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 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论