move semaphore acquisition outside begin/ensure block