C++ Logo

std-proposals

Advanced search

[std-proposals] Prevent re-entry but re-queue the event

From: Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>
Date: Tue, 11 Jul 2023 12:00:22 +0100
Back in February I posted here about having language support to
prevent the re-entry of functions, which would be particularly useful
in event-driven systems (such as how wxWidgets processes events such
as BUTTON_CLICK from widgets on the screen).

Back in February I proposed two alternatives to re-entering the function:
(1) Skip
(2) Wait

So with 'Skip', the reentry of the function is prevented and the event
is discarded.

With 'Wait', the second attempt to enter the function is prevented but
the thread freezes and then later becomes unfrozen after the function
has been exited by another thread. (Obviously you can't 'wait' for the
same thread to exit).

The latest draft I had for my paper was Draft No. 2:

    http://www.virjacode.com/download/noreentry_latest_draft.pdf

I have come up with one more possibility to go with the previous two:
(3) Re-queue

The third possibility is that the event is not processed, but it gets
re-appended to the end of the event queue (in the hope that it will be
processed later).

In order to facilitate how the re-queuing would work, I propose that a
class such as "wxEvtHandler" would have a new method called
"__requeue", which would be coded something like:

    void wxEvtHandler::__requeue( void
(wxEvtHandler::*p_method)(wxEvent&), wxEvent &e)
    {
        this->CallAfter(p_method, e);
    }

And so then whenever you want to write an event handler that should
not be re-entered, but for which you don't want to discard events, you
write:

    void MyClass::MyEventHandler(wxEvent&) noreentry_this_object(requeue)
    {
        /* You're guaranteed that this method won't be re-entered */
    }

Received on 2023-07-11 11:00:33