What is std::jthread in c++20?

std::jthread is like std::thread, only without the stupid. See, std::thread‘s destructor would terminate the program if you didn’t join or detach it manually beforehand. This led to tons of bugs, as people would expect it to join on destruction.

jthread fixes this; it joins on destruction by default (hence the name: “joining thread”). It also supports a mechanism to ask a thread to halt execution, though there is no enforcement of this (aka: you can’t make another thread stop executing).

At present, there is no plan to deprecate std::thread.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)