C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Make std::thread not joinable after thread function ends.

From: Jason McKesson <jmckesson_at_[hidden]>
Date: Sun, 18 Jun 2023 17:17:28 -0400
On Sun, Jun 18, 2023 at 4:26 PM Smith, Jim via Std-Proposals
<std-proposals_at_[hidden]> wrote:
>
> Hi All,
>
> It would be convenient if std::thread would automatically become not joinable after the thread function ends.

This just creates a race condition:

```
if(thread.joinable())
  thread.join();
```

Is this functioning code? It looks like it *should* be but it isn't.
The answer to the `joinable` question is out-of-date the moment after
you call the function. If the thread function exits *after* the
joining thread asks if it is joinable, then the call to `join` will
fail.

So even if this were solving a problem, it's creating a new problem in turn.

Received on 2023-06-18 21:17:41