Semaphore implementation