Subj : trying to make own version of pthread_exit() To : comp.programming.threads From : JS Date : Tue Mar 22 2005 03:34 pm I am trying to make my own implementation of pthread_exit(). I have read: http://www.llnl.gov/computing/tutorials/workshops/workshop/pthreads/man/pthread_exit.html To prevent confusion I call the funtions mythread instead of pthread. When a thread calls mythread_exit() it should be terminated safely. But it should also store a "termination status void pointer" that any joining threads can access. When I create a new thread, start_function is called which then calls mythread_exit with the pointer that it returns. Is this the right use of pthread_exit function? I store the return value that start_function produces in a void pointer k. I can't seem to get k printed to check if the return value was stored in k: #include #include #include typedef int mythread_t; #define STACK_SIZE 1024 struct pcb { void *(*start_routine) (void *); void *arg; jmp_buf state; int stack[STACK_SIZE]; }; typedef struct _mythread_attr_t { } mythread_attr_t; static struct pcb first_thread; struct pcb *current = &first_thread; struct pcb *ready = NULL; int mythread_create (mythread_t *threadp, const mythread_attr_t *attr, void *(*start_routine) (void *), void *arg) { int *state_pointer; int local_occ; struct pcb *pcb_pointer; pcb_pointer = (struct pcb *) malloc(sizeof(struct pcb)); if(pcb_pointer == NULL) { exit(-1); } pcb_pointer->start_routine = start_routine; pcb_pointer->arg = arg; if(setjmp(pcb_pointer->state)) { current->start_routine(current->arg); printf("Thread returned - Everything is stopped\n"); exit(0); } int JB_BP = 3; int JB_SP = 4; state_pointer = (int *) &pcb_pointer->state; local_occ = state_pointer[JB_BP] - state_pointer[JB_SP]; state_pointer[JB_BP] = (int) (pcb_pointer->stack + STACK_SIZE); state_pointer[JB_SP] = (int) state_pointer[JB_BP] - local_occ; ready = pcb_pointer; *threadp = (int) pcb_pointer; return 0; } void mythread_exit(void *retval){ void * k; k = retval; printf("%d",k); } void *start_function(void *arg){ int x = 22; int *ip; ip = &x; mythread_exit(ip); return ip; } int main(void){ mythread_t id; mythread_create(&id, NULL, start_function, NULL); getchar(); } .