Rewriting thread, critical section, mutex and semaphore code