Implementation of thread context switching using ucontext, signals, and timers