std::thread
?std::thread
?std::jthread The class jthread represents a single thread of execution. It has the same general behavior as std::thread, except that jthread automatically rejoins on destruction, and can be cancelled/stopped in certain situations.
Concurrency occurs when multiple copies of a program run simultaneously while communicating with each other. Simply put, concurrency is when two tasks are overlapped.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With