Fix the thread-related segfault