From 054e21a32c8b219b2e99aa86376c0de134809708 Mon Sep 17 00:00:00 2001 From: p9ya4sf57 <2573478641@qq.com> Date: Mon, 4 Jul 2022 09:55:14 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9B=E5=BB=BA=E7=BA=BF=E7=A8=8B=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pthread.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 pthread.c diff --git a/pthread.c b/pthread.c new file mode 100644 index 0000000..5ab9e58 --- /dev/null +++ b/pthread.c @@ -0,0 +1,66 @@ +#include "pthread.h" + + +/* +* pthread.c +* +* POSIX threads library based on linux-0.11 +* +* Copyright (C) 2008 All rights reserved. +* +* 这个里面没有写多少注释,都是很简单的 +*/ + +_syscall2(int, create_thread, unsigned long, start, void*, arg); +_syscall2(int, syspthread_join, pthread_t, thread, void*, value_ptr); +_syscall1(int, endthread, int, value); + +int pthread_attr_init(pthread_attr_t* attr) /*这个实验没有必要用到这个初始化函数*/ +{ + ;;;;; + return 0; +} +int pthread_create(pthread_t* thread, const pthread_attr_t* attr, void* (*start)(void*), void* arg) +{ + int id = 0; + if (!thread) return EINVAL; + + id = create_thread((unsigned long)start, (int*)arg); + + /*printf("here after create_thread!\n");*/ + /*stop: goto stop;*/ + if (id < 0) return errno; + *thread = id; + return id; +} + +void pthread_exit(void* value_ptr) +{ + endthread((int)value_ptr); +} +int pthread_join(pthread_t thread, void** value_ptr) +{ + syspthread_join(thread, value_ptr); + return 0; +} + + + + + + + + + + + + + + + + + + + + +