Implemented the semaphore for events.