Trouble with semaphore library