Added semaphores and unittests