Jim was suggesting, that a finished thread would return .joinable() as false

 

One could then expect (according to the name) that .join() would fail then.

 

 

Alternatively one could suggest to introduce a new non-blocking function to ask, whether a thread has finished execution.

@Jim, not sure, whether this was your actual intention, instead of also changing the behavior of .join()

 

Apart from that, changing the behavior would break existing code.


 

-----Ursprüngliche Nachricht-----
Von: Ville Voutilainen via Std-Proposals <std-proposals@lists.isocpp.org>
Gesendet: So 18.06.2023 23:34
Betreff: Re: [std-proposals] Make std::thread not joinable after thread function ends.
An: std-proposals@lists.isocpp.org;
CC: Ville Voutilainen <ville.voutilainen@gmail.com>;
On Mon, 19 Jun 2023 at 00:17, Jason McKesson via Std-Proposals
<std-proposals@lists.isocpp.org> wrote:
>
> On Sun, Jun 18, 2023 at 4:26 PM Smith, Jim via Std-Proposals
> <std-proposals@lists.isocpp.org> 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.
--
Std-Proposals mailing list
Std-Proposals@lists.isocpp.org
https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals