using semaphore to use less cpu