c - Segfault when using swapcontext() in user level thread library? -



c - Segfault when using swapcontext() in user level thread library? -

i trying implement user=level thread library using setcontext/getcontext/ect... library of scheme calls. life of me cannot figure out why getting segfault when seek swap contexts in waitall , yield functions below. have tried debugging print statement, valgrind, , gdb extensively still haven't managed create sense of yet. thanks!

static struct node* ready; static ucontext_t main; void ta_libinit(void) { ready = malloc(sizeof(struct node)); getcontext(&main); ready -> thread = main; ready -> ismain = 0; ready -> next = null; return; } void ta_create(void (*func)(void *), void *arg) { ucontext_t thread; // prepare ptrs unsigned char *stack = (unsigned char *)malloc(stacksize); assert(stack); /* set thread*/ getcontext(&thread); thread.uc_stack.ss_sp = stack; thread.uc_stack.ss_size = stacksize; thread.uc_link = &main; makecontext(&thread, (void (*)(void))func, 1, arg); fifo_append(thread, &ready); return; } void ta_yield(void) { // switches next thread on ready queue, pushing current // thread back. struct node* current = fifo_pop(&ready); fifo_push(current, ready); swapcontext(&(current -> thread), &(ready -> thread)); return; } int ta_waitall(void) { // called calling programme - wait threads finish. while (ready -> next != null) { struct node *current = fifo_pop(&ready); swapcontext(&current -> thread, &ready -> thread); // took out testing purposes. //free((&current -> thread.uc_stack)); //free(current); } homecoming -1; }

c linux multithreading fiber

Comments

Popular posts from this blog

java Multi query from Mysql using netbeans -

c# - DotNetZip fails with "stream does not support seek operations" -

c++ - StartServiceCtrlDispatcher don't can access 1063 error -