Fixed race conditions in thread_exit for children/parent relations