== Why is this an issue?

``++std::jthread++``, introduced in {cpp}20, is a wrapper around ``++std::thread++``. This way, it has the same functionalities as ``++std::thread++``, making the substitution straightforward while adding two interesting behaviors:

* It joins by default in its destructor. If a ``++std::thread++`` was not joined or detached before being destroyed, a call to ``++std::terminate++`` was made. This behavior can’t happen with ``++std::jthread++``.
* It can be canceled or stopped in some situations by calling ``++request_stop()++``.

This rule raises an issue when ``++std::thread++`` is used.


=== Noncompliant code example

[source,cpp,diff-id=1,diff-type=noncompliant]
----
void backgroundTask();
int main() {
  std::thread t(backgroundTask); // Noncompliant
  t.join();
}
----


=== Compliant solution

[source,cpp,diff-id=1,diff-type=compliant]
----
void backgroundTask();
int main() {
  std::jthread jt(backgroundTask);
}
----


== Resources

=== Documentation

* {cpp} reference - https://en.cppreference.com/w/cpp/thread/jthread[std::jthread]

=== External coding guidelines

* {cpp} Core Guidelines - https://github.com/isocpp/CppCoreGuidelines/blob/e49158a/CppCoreGuidelines.md#cp25-prefer-gsljoining_thread-over-stdthread[CP.25: Prefer `gsl::joining_thread` over `std::thread`]

