C++ Logo

std-proposals

Advanced search

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

From: Ville Voutilainen <ville.voutilainen_at_[hidden]>
Date: Mon, 19 Jun 2023 00:34:06 +0300
On Mon, 19 Jun 2023 at 00:17, Jason McKesson via Std-Proposals
<std-proposals_at_[hidden]> wrote:
>
> 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.

Why would the call to join() fail? It's perfectly okay to call join()
after the thread
function has exited.

Received on 2023-06-18 21:34:20