public void waitForEvent(long timeout) {
Thread thread = Thread.currentThread();
Semaphore semaphore = _semaphores.get(thread);
if (semaphore == null) {
semaphore = new Semaphore(1, true);
semaphore.drainPermits();
_semaphores.putIfAbsent(thread, semaphore);
}
semaphore = _semaphores.get(thread);
try {
semaphore.tryAcquire(timeout, TimeUnit.MILLISECONDS);