implementation of semaphore and lock for async calls