Thread and ThreadPool functions.