Fix infinitely spawning threads problem.