working sync with semaphores