C++ Logo

std-proposals

Advanced search

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

From: Sebastian Wittmeier <wittmeier_at_[hidden]>
Date: Sun, 18 Jun 2023 23:45:52 +0200
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_at_[hidden]> Gesendet:So 18.06.2023 23:34 Betreff:Re: [std-proposals] Make std::thread not joinable after thread function ends. An:std-proposals_at_[hidden]; CC:Ville Voutilainen <ville.voutilainen_at_[hidden]>; 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. -- Std-Proposals mailing list Std-Proposals_at_[hidden] https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals

Received on 2023-06-18 21:45:53