Thread synchronization using Semaphore