C++ Logo


Advanced search

Re: [std-proposals] Allow std::optional to give pointer to yet-to-be-constructed

From: Ville Voutilainen <ville.voutilainen_at_[hidden]>
Date: Tue, 13 Dec 2022 17:23:19 +0200
On Tue, 13 Dec 2022 at 17:16, Thiago Macieira via Std-Proposals
<std-proposals_at_[hidden]> wrote:
> On Tuesday, 13 December 2022 09:47:41 -03 Frederick Virchanza Gotham via Std-
> Proposals wrote:
> > Just yesterday I wanted to do two things:
> > (1) Show a dialog box
> > (2) Start a new thread
> >
> > My debacle however was as follows:
> > a) The constructor for the DialogBox needs the stop_token of the thread
> > b) The entry point for the thread needs the address of the DialogBox
> Is it not permitted to get the stop token of an unstarted jthread? The two
> implementations I can see right now won't change that address after you assign
> to the jthread, starting it.

jthread can be constructed with a function that takes a user-provided
stop token instead of using the one provided the jthread,
so that could be used to solve this debacle. Create the token, pass it
to the dialog, pass it to the thread.

Received on 2022-12-13 15:23:32