Vote count:
0
First time I am working with ucontext_t. My program dies after I call first swapcontext(). The program prints out the function I called, but then does nothing else.
struct TCB_t *RunQ;
struct TCB_t
{
struct TCB_t * next;
struct TCB_t * previous;
ucontext_t context;
};
void init_TCB (struct TCB_t *tcb, void *function, void *stackP, int stack_size)
{
memset(tcb, '\0', sizeof(struct TCB_t));
getcontext(&tcb->context);
tcb->context.uc_stack.ss_sp = stackP;
tcb->context.uc_stack.ss_size = (size_t)stack_size;
makecontext(&tcb->context, function, 0);
}
static void functionOne()
{
puts("start f1");
puts("finish f1");
}
void start_thread(void (*function)(void))
{
struct stack * stackP = (struct stack*)malloc(sizeof(struct stack));
struct TCB_t * tcb = (struct TCB_t *)malloc(sizeof(struct TCB_t));
init_TCB (tcb, function, stackP, 8192);
RunQ = tcb;
}
void run()
{
ucontext_t parent;
getcontext(&parent);
printf("\n -------Printing list Start-2------ \n");
swapcontext(&parent, &(RunQ->context));
printf("\n -------Printing list Start-4------ \n");
}
int main(void)
{
start_thread(functionOne);
run();
}
The output I get is -------Printing list Start-2------ start f1 finish f1 So it swapcontext() and dies. Is there a next step I am missing?
asked 1 min ago
program dies after swapcontext()
Aucun commentaire:
Enregistrer un commentaire