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 10:56:28 +0000
On Tue, Feb 14, 2023 at 10:52 AM Frederick Virchanza Gotham
<cauldwell.thomas_at_[hidden]> wrote:
>
> On Tue, Feb 14, 2023 at 9:32 AM Frederick Virchanza Gotham wrote:
> >
> > Here's a sensible combination:
> >
> > void Func(void)
> > noreentry_this_object(prevent_other_threads:skip)
> > noreentry_all_objects(prevent_other_threads:wait)
>
>
> I want to show just how much typing this would save. The following code snippet:
<snip>
> // The next line allows all kinds re-entry for the same thread
> if ( id_for_all != std::this_thread::get_id() )
> {
> if ( false == myguard_this.try_lock() )


I realise that there's a race condition here between the checking of
"id_for_all" and the locking of the guards. The code was not intended
to be a perfect implementation. Actually this just goes to show that
the real solution would be even more complicated -- which is why it
would be nice to just be able to write "noreentry" after the name of a
function, and let the compiler have the headache for you.

Received on 2023-02-14 10:56:40