#define __LIBRARY__ #include #include #include #include #include #include #include #include #define PAGE_SIZE 4096 int pthread_create(pthread_t *thread,const pthread_attr_t* attr,void* (*start_routine)(void *),void* arg) { pthread_t thread_id; if(thread == NULL || start_routine == NULL) { printf("Error:Thread or func_addr is NULL!!!\n"); exit(0); } if(attr != NULL && attr->stacksize > PAGE_SIZE) return EINVAL; thread_id = thread_fork(attr,start_routine,arg); if(thread_id == -1) { printf("Error:New thread creating failed!!!\n"); return errno; } if(thread_id > 0) { (*thread) = thread_id; return 0; } printf("Error:pthread_create error!\n"); return -1; } int pthread_join(pthread_t thread,void** value_ptr) { if(thread <=0) { printf("Error:Invalid thread for pthread_join!\n"); exit(0); } if(value_ptr == NULL) { printf("Error:value_ptr is invalid!\n"); exit(0); } thread_join(thread,value_ptr); return 0; } void pthread_exit(void* value_ptr) { thread_exit(value_ptr); }