Date: Mon, 11 Dec 2023 20:42:23 +0100
pon., 11 gru 2023 o 18:26 Thiago Macieira via Std-Proposals
<std-proposals_at_[hidden]> napisaĆ(a):
>
> On Monday, 11 December 2023 08:45:31 PST Valentin Palade wrote:
> > Doing a local copy as Jonathan suggests, will make no difference, with
> > threads running concurrently, we can still have use_count() return anything
> > between 1 and 5.
> >
> > Or am I missing something?
>
> No. It can be between 1 and 5.
>
> But if it's 1, then you have the only copy and there is no other thread seeing
> this object. The number can't change unless the current thread changes it.
>
But all threads can return 5 too. As check is done before decrement
every one can observe the state before it.
And this means no thread can get 1 and acquire the last instance.
We need to guarantee that one thread will be the least instance.
Probably best will be a combination of two approaches:
move away from the old pointer and then use `resurect` on a new instance.
Then we have a guarantee that exactly one thread will get the last instance.
(and this operation can be atomic if we return this new instance of pointer)
btw small bikeshedding, I think this operation should be named
"collapse" like in wave-function where you have multiple
place where you can detect particle (pointers copies)
but when you try to detect where a particle is, only one detector
can have it (wave-function collapses to one point).
> --
> Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
> Software Architect - Intel DCAI Cloud Engineering
>
>
>
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
<std-proposals_at_[hidden]> napisaĆ(a):
>
> On Monday, 11 December 2023 08:45:31 PST Valentin Palade wrote:
> > Doing a local copy as Jonathan suggests, will make no difference, with
> > threads running concurrently, we can still have use_count() return anything
> > between 1 and 5.
> >
> > Or am I missing something?
>
> No. It can be between 1 and 5.
>
> But if it's 1, then you have the only copy and there is no other thread seeing
> this object. The number can't change unless the current thread changes it.
>
But all threads can return 5 too. As check is done before decrement
every one can observe the state before it.
And this means no thread can get 1 and acquire the last instance.
We need to guarantee that one thread will be the least instance.
Probably best will be a combination of two approaches:
move away from the old pointer and then use `resurect` on a new instance.
Then we have a guarantee that exactly one thread will get the last instance.
(and this operation can be atomic if we return this new instance of pointer)
btw small bikeshedding, I think this operation should be named
"collapse" like in wave-function where you have multiple
place where you can detect particle (pointers copies)
but when you try to detect where a particle is, only one detector
can have it (wave-function collapses to one point).
> --
> Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
> Software Architect - Intel DCAI Cloud Engineering
>
>
>
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
Received on 2023-12-11 19:42:36