🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c++
Article #1010

Re: A better experimental::scope_exit

#1010
From: Scott Lurndal
Date: Mon, 23 Nov 2026 16:37
56 lines
2525 bytes
Bonita Montero <Bonita.Montero@gmail.com> writes:
>Am 23.11.2026 um 13:26 schrieb David Brown:
>
>> template<typename T>
>> struct scope_exit {
>>      T f;
>>      scope_exit(T f) : f(f) { }
>>      ~scope_exit() { f(); }
>> };
>
>You can't cascade multiple exits with that. This means if you have
>several manipulations on a data structure and you want to revert them
>if an exception occurs the destructor revers the changes so far. But
>if nothing happens in that sense you simply call .disable() on the
>last node in the chain and all dependent nodes are also disabled.
>Just as a commit in a databse.

KISS.  This is from a 1992-ish port of Unix to run as
an actor for the Chorus microkernel.

//
//      Destructor: undo what fork has done upon failure.
//
tForkFailure::~tForkFailure()
{
        if (ret == 0) {
                return;
        }

        if (PActUI != NULL) {
                procp->Mem.Exit(ChildCap);
        }

                //
                // XXXKYS: the DeleteAll() needs to take 
                // into account that some of the LWPs
                // in the list may be zombies.
                //
        procp->LwpList.DeleteAll();

        if (rgn == B_TRUE) {
                procp->Rgn.ShmExit(CrLwp, procp);
        }

        if (file == B_TRUE) {
                procp->File.ForkUndo();
        }

        procp->ProcRlim->rlFree(nlwp + 1);
        procp->ProcCred->CrFree(nlwp + 1);

        procp->UidQuota.FreeProc(B_TRUE, total_lwp, 1);
}

Aside: The KYS referenced in the comment is now a VP at Microsoft.
Technical Details
Message-ID: <gZZMS.79729$Mef7.47357@fx15.iad>
Path: mbox-mo1.pugleaf.net!news-wdc.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx15.iad.POSTED!not-for-mail
References: <11dsk17$8ske$2@raubtier-asyl.eternal-september.org> <11e1bd7$1rqma$1@dont-email.me> <11e1gtl$1u1jq$1@raubtier-asyl.eternal-september.org>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-wdc.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx15.iad.POSTED!not-for-mail
X-newsreader: xrn 9.03-beta-14-64bit
Sender: scott@dragon.sl.home (Scott Lurndal)
From: scott@slp53.sl.home (Scott Lurndal)
Reply-To: slp53@pacbell.net
Subject: Re: A better experimental::scope_exit
Newsgroups: comp.lang.c++
References: <11dsk17$8ske$2@raubtier-asyl.eternal-september.org> <11e1bd7$1rqma$1@dont-email.me> <11e1gtl$1u1jq$1@raubtier-asyl.eternal-september.org>
Lines: 56
Message-ID: <gZZMS.79729$Mef7.47357@fx15.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Mon, 23 Nov 2026 16:37:32 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Mon, 23 Nov 2026 16:37:32 GMT
X-Received-Bytes: 2300