pthreads: use semaphore protection for the thread list