fixing posix semaphores and added tests