Clean up the thread startup code by moving common code into a new create_thread () function.