switch to std::thread and std::atomic