C++ Logo


Advanced search

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

From: Thiago Macieira <thiago_at_[hidden]>
Date: Wed, 21 Jun 2023 17:44:56 -0700
On Wednesday, 21 June 2023 14:06:01 PDT Jonathan Wakely via Std-Proposals
> It's trivial to implement std::future::is_ready() in terms of
> std::future::wait_for(0s) but I don't know how to implement a
> std::thread::try_join() or std::thread::join_will_not_block() portably.

    return false;

Is a correct cross-platform implementation in the absence of a non-blocking or
timed lower-level join function. It can't be distinguished from a real
implementation that ran just a few cycles before the thread did actually exit.

And those instructions may take centuries to execute, so it's perfectly fine to
keep returning false for that long. You can't busy-wait for to exit, because
the act of busy-waiting may prevent the other thread from executing the
exiting code.

Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel DCAI Cloud Engineering

Received on 2023-06-22 00:44:59