updated version with solving the problem without busy waiting using Semaphore Block Queue.