In implementing threads, it will be necessary to transfer control from one thread to another.
CurrentThread is global pointer to thread control block for executing thread and executes switch below to give control to another thread pointed to by next_thread.
void switch(thread_t *next_thread) { CurrentThread->SP = SP; CurrentThread = next_thread; SP = CurrentThread->SP; return; }