The main requirements behind resurrect are:
  1. lock free
  2. preserving the control block that was allocated initially for the object.
Because of the second idea, we cannot efficiently move away from the old pointer as we'll need to reallocate the control block.

I like the idea of using "collapse" and the reasoning behind it. Will take it into consideration if/when moving ahead with the proposal.


On Mon, Dec 11, 2023 at 9:42 PM Marcin Jaczewski <> wrote:
pon., 11 gru 2023 o 18:26 Thiago Macieira via Std-Proposals
<> 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) - thiago (AT)
>    Software Architect - Intel DCAI Cloud Engineering
> --
> Std-Proposals mailing list