C++ Logo

std-proposals

Advanced search

Re: [std-proposals] std::thread::first_ever

From: Thiago Macieira <thiago_at_[hidden]>
Date: Sun, 30 Apr 2023 09:20:10 -0700
On Sunday, 30 April 2023 03:37:48 PDT Frederick Virchanza Gotham via Std-
Proposals wrote:
> When we say 'the main thread', 99% of the time we are talking about
> the very first thread that the program started. In rare cases, if the
> first thread has terminated, we might refer to the second thread as
> 'the main thread'. Or if the second has also terminated, maybe we'll
> call the third thread the 'main thread'.

No, we do not.

The main thread is the thread in which main() was called. It is very different
from any other thread. So we may refer to it as the main() thread.

As Mike replied and you've discovered, you can't exit from main() without
either terminating the entire process or using some non-standard
functionality, which I'm not convinced is allowed even under those libraries.
Therefore, the thread in which main() was run is always still running.

Besides, on some systems, the first thread allocated to a process may not be
the one in which main() was run. Those systems may run some background book-
keeping tasks running on those threads. Therefore, I think the wording
shouldn't be "the first thread", at least not without some extra qualification

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

Received on 2023-04-30 16:20:11