semaphore initialization and thread creation