refactor semaphore barrier to look more like the monitor version