Implement thread synchronization using Semaphores (Project 4).