Rewrite thread support code

Use the abstractions, which are based on std::thread