Date: Mon, 17 Jul 2023 07:37:34 +0100
On Mon, Jul 17, 2023 at 4:58 AM Thiago Macieira via Std-Proposals
<std-proposals_at_[hidden]> wrote:
>
> On Sunday, 16 July 2023 02:53:22 PDT Frederick Virchanza Gotham wrote:
> > I've made it generic, so maybe they're more interested in returning a
> > decremented semaphore or a true atomic_flag?
>
> Why would you want to do that?
>
> Threading synchronisation objects need to be globally accessible, because
> that's their purpose. Two threads can't refer to the same object if it's
> returned on the stack by a function, since by definition two threads have
> different stacks.
>
> Please give a better example.
The object doesn't have to be constructed on the stack. Yesterday I
posted code that took the return value of a function and stored it in
a global "std::optional" variable.
Anton gives loads of good examples in his paper, such as:
widget setup_widget(int x) {
widget w;
w.set_x(x);
return w;
}
Here's Anton's paper:
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p2025r0.html
<std-proposals_at_[hidden]> wrote:
>
> On Sunday, 16 July 2023 02:53:22 PDT Frederick Virchanza Gotham wrote:
> > I've made it generic, so maybe they're more interested in returning a
> > decremented semaphore or a true atomic_flag?
>
> Why would you want to do that?
>
> Threading synchronisation objects need to be globally accessible, because
> that's their purpose. Two threads can't refer to the same object if it's
> returned on the stack by a function, since by definition two threads have
> different stacks.
>
> Please give a better example.
The object doesn't have to be constructed on the stack. Yesterday I
posted code that took the return value of a function and stored it in
a global "std::optional" variable.
Anton gives loads of good examples in his paper, such as:
widget setup_widget(int x) {
widget w;
w.set_x(x);
return w;
}
Here's Anton's paper:
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p2025r0.html
Received on 2023-07-17 06:37:46