Moved thread api functions into separate file.