C++ Logo

std-proposals

Advanced search

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:
>
> Then please add to your paper how the programmer is allowed to choose that the
> 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:
(a) The same thread that has already entered
(b) A different thread than the one that has already entered

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
re-entries for other threads
* Skip all re-entries for the same thread, but block all re-entries
for other threads

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
thread, block for other threads
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
same thread, block for other threads
b2y: Prevent re-entry only by other threads, across all objects, and
always block

And the syntaxes could be:

a1x: void Func(void) noreentry_this_object(prevent_same_thread)
 // The 'skip' here is implicit
b1x: void Func(void) noreentry_this_object(prevent_other_threads:skip)
ab1x: void Func(void)
noreentry_this_object(prevent_same_thread,prevent_other_threads:skip)
ab2x: void Func(void)
noreentry_this_object(prevent_same_thread,prevent_other_threads:wait)
b2x: void Func(void) noreentry_this_object(prevent_other_threads:wait)
a1y: void Func(void) noreentry_all_objects(prevent_same_thread)
 // The 'skip' here is implicit
b1y: void Func(void) noreentry_all_objects(prevent_other_threads:skip)
ab1y: void Func(void)
noreentry_all_objects(prevent_same_thread,prevent_other_threads:skip)
ab2y: void Func(void)
noreentry_all_objects(prevent_same_thread,prevent_other_threads:wait)
b2y: void Func(void) noreentry_all_objects(prevent_other_threads:wait)

And finally, it could be possible to mark a member function both with
"noreentry_this_object" and also "noreentry_all_objects", for example:

void Func(void) noreentry_this_object(prevent_same_thread)
noreentry_all_objects(prevent_same_thread,prevent_other_threads:wait)

Received on 2023-02-14 09:12:40