first version of semaphore implementation