std::thread:
1std::thread t([] { /* work */ });2t.join(); // must not forget!
std::jthread (C++20):
1std::jthread t([](std::stop_token stoken) {2 while (!stoken.stop_requested()) {3 // work4 }5});6// Automatically joined and stop requested on destruction
Use std::jthread — it's safer and more convenient.