refactor using atomics instead of semaphores for queue