Replace while() usleep loop with a proper semaphore
Release semaphore in case the thread creation fails