Fix a race at thread creation