AMD interview question

c++ threads usage, semaphore, how to write thread safe code