# Re: [std-proposals] int Func(void) noreentry(-1)

From: Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>
Date: Tue, 14 Feb 2023 09:12:29 +0000
On Tue, Feb 14, 2023, Thiago Macieira wrote:
>
> reentrancy is prevented by a wait until the other thread finishes or, if it's
> not possible, why you don't think it needs to be part of this implementation.

Well how about we run through an exhaustive list of possibilities.

Firstly, a re-entry attempt can be made by:

And then this re-entry attempt can be:
(1) Skipped (i.e. immediately return -1 and totally skip the routine)
(2) Blocked (i.e. wait until the routine has been exited and then enter it)

So to start with, this gives us four possibilities: a1, a2, b1, b2

We can however discard a2 because it's not possible, so that leaves us
with: a1, b1, b2

If we're dealing with a member function rather than a normal function,
then we can prevent re-entry for:
(x) *this
(y) all objects

So now the possibilities are: a1x, b1x, b2x, a1y, b1y, b2y

If we want to prevent all re-entries, (i.e. prevent for 'a' and also
prevent for 'b'), then that gives us two new possibilities: ab1x, ab1y
So now the possibilities are:

a1x, b1x, ab1x, b2x, a1y, b1y, ab1y, b2y

We can allow further customisation of combining 'a' and 'b' together:
* Skip all re-entries for the same thread, and also skip all
* Skip all re-entries for the same thread, but block all re-entries

Then this means that every combination of 'ab' can be done four ways:
a1b1, a1b2, a2b1, a2b2.
However since we can't block for the same thread, that list becomes
shorter: a1b1 a1b2.
Since 'a' will never be followed by a '2', we can make shorthand out
of those two: ab1, ab2
So every combination of 'ab' and become either 'ab1' or 'ab2'.
So we add two new possibilities: ab2x, ab2y
So now we have a total of 10 different possibilities:

a1x, b1x, ab1x, ab2x, b2x, a1y, b1y, ab1y, ab2y, b2y

which verbosely described are:

a1x: Prevent re-entry only by the same thread, only for *this, and always skip
b1x: Prevent re-entry only by other threads, only for *this, and always skip
ab1x: Prevent any kind of re-entry, only for *this, and always skip
ab2x: Prevent any kind of re-entry, only for *this, skip for the same
b2x: Prevent re-entry only by other threads, only for *this, and always block
a1y: Prevent re-entry only by the same thread, across all objects,
and always skip
b1y: Prevent re-entry only by other threads, across all objects, and
always skip
ab1y: Prevent any kind of re-entry, across all objects, and always skip
ab2y: Prevent any kind of re-entry, across all objects, skip for the
b2y: Prevent re-entry only by other threads, across all objects, and
always block

And the syntaxes could be:

// The 'skip' here is implicit
ab1x: void Func(void)
ab2x: void Func(void)
// The 'skip' here is implicit