C++ Logo

std-proposals

Advanced search

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

From: Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>
Date: Thu, 16 Feb 2023 16:16:29 +0000
Without even going into the technical details . . . . can I just flow
the question:
        Are people here on the mailing list keen on the idea of being
able to prevent the re-entry of a function simply by writing something
like "noreentry" after its name?

It's already possible since C++11 to prevent the re-entry of a
function, for example by using 'std::mutex' or 'std::atomic_flag', so
I'm not talking about making something possible that was previously
impossible.

But if we can prevent the re-entry of a function simply by writing
something like "noreentry" after its name, then it saves a lot of
typing and also it lessens the risk of introducing bugs. Furthermore,
if the prevention scheme is very complicated -- for example if we're
dealing with a member function and we want to prevent re-entry for the
same thread and the same object but allow re-entry in all other
circumstances except when the same thread tries to re-enter for a
different object, then the locks and locking code can become quite
complex and susceptible to introducing bugs.

When re-entry of a function is prevented, there could be two
possibilities: (1) Immediately return (i.e. skip the call), or (2)
Block (i.e. wait until the function has been exited). In event-driven
frameworks, in particular the event-handling systems you have in
desktop GUI programs, it makes sense to immediately return if an
attempt is made to re-enter an event handler. For example if you're
writing a program to defragment hard disks, and you process the Click
event for the "Defrag Now" button, you don't want that event handler
to be re-entered in any circumstances.

So before we even talk about how we would implement this feature, I'll
just ask: Who here is keen on the idea of being able to simply write
"noreentry" after the name of a function, and then letting the
compiler deal with the headache of how to manage all the locks?

Received on 2023-02-16 16:16:42