modified semaphore behavior to reduce duration inside semaphore