/****************************************************************************** * * P S E U D O C O D E * ****************************************************************************** //global variables: curr // pointer to currently running process ready_queue // header for the jobs waiting to run.... main() { char ss1[STACK_SIZE], ss2[STACK_SIZE], ss3[STACK_SIZE]; start_thread( function_1, NULL, &ss1 ); // create a thread that will run function_1 start_thread( function_2, NULL, &ss2 ); start_thread( function_3, NULL, &ss3 ); run(); // all the threads start running, this call never returns } start_thread(function, argv, ss) // keep argv NULL { if ready_queue not initialized -- InitQueue(ready_queue); // or do it in main. pcb = malloc(); init_context( pcb, function, ss ); enQueue( ready_queue, pcb ); } run() // only called once, from main { getcontext( parent ); curr = dequeue( ready_queue ); swapcontext( parent, &curr->context ); } void yield() // switch to another thread { next = deQueue( run_queue ); prev = curr; curr = next; enQueue( run_queue, prev); swapcontext( prev->context, next->context ); // the actual context switch } enQueue( ... ) { ... } deQueue( ... ) { ... } InitQueue( ... ) { ... } function_1( ... ) { ... } ... */