From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: <69de78bb2dcc84f725ceea4b529c1ec4@9fs.org> To: 9fans@cse.psu.edu Subject: Re: [9fans] how to avoid a memset() optimization From: nigel@9fs.org MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="upas-jdeeuxwxxiwphgjsnbqyjlepxe" Date: Mon, 6 Jan 2003 10:47:07 +0000 Topicbox-Message-UUID: 3bb4448e-eacb-11e9-9e20-41e7f4b1d025 This is a multi-part message in MIME format. --upas-jdeeuxwxxiwphgjsnbqyjlepxe Content-Disposition: inline Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit Or failed = 1; if ((res1 = lock(A) != 0) if ((res2 = lock(B) != 0) { if ((res3 = lock(C) != 0) { foo(res1, res2, res3); failed = 0; } if (res3 != 0) release(C); if (res2 != 0) release(B); if (res1 != 0) release(A); return failed; avoiding the goto. Further, if release(nil) is implemented as a noop you can have failed = 1; if ((res1 = lock(A) != 0) if ((res2 = lock(B) != 0) { if ((res3 = lock(C) != 0) { foo(res1, res2, res3); failed = 0; } release(C); release(B); release(A); return failed; --upas-jdeeuxwxxiwphgjsnbqyjlepxe Content-Type: message/rfc822 Content-Disposition: inline Received: from 9fs.org ([192.168.100.103]) by 9fs.org; Mon Jan 6 10:37:12 GMT 2003 Received: from mail.cse.psu.edu ([130.203.4.6]) by 9fs.org; Mon Jan 6 10:37:08 GMT 2003 Received: from psuvax1.cse.psu.edu (psuvax1.cse.psu.edu [130.203.8.6]) by mail.cse.psu.edu (CSE Mail Server) with ESMTP id E9BAE199B3; Mon, 6 Jan 2003 05:36:05 -0500 (EST) Delivered-To: 9fans@cse.psu.edu Received: from mercury.bath.ac.uk (mercury.bath.ac.uk [138.38.32.81]) by mail.cse.psu.edu (CSE Mail Server) with ESMTP id 572A619995 for <9fans@cse.psu.edu>; Mon, 6 Jan 2003 05:35:17 -0500 (EST) Received: from news by mercury.bath.ac.uk with local (Exim 3.12 #1) id 18VULV-0006kM-00 for 9fans@cse.psu.edu; Mon, 06 Jan 2003 10:19:01 +0000 Received: from GATEWAY by bath.ac.uk with netnews for 9fans@cse.psu.edu (9fans@cse.psu.edu) To: 9fans@cse.psu.edu From: Ralph Corderoy Message-ID: <3afa.3e16dd11.67d1a@blake.inputplus.co.uk> Organization: InputPlus Ltd. References: <38aa463bafe23035decff6b0364f7553@plan9.bell-labs.com>, <20021119103808.B13548@unicorn.math.spbu.ru> Subject: Re: [9fans] how to avoid a memset() optimization Sender: 9fans-admin@cse.psu.edu Errors-To: 9fans-admin@cse.psu.edu X-BeenThere: 9fans@cse.psu.edu X-Mailman-Version: 2.0.11 Precedence: bulk Reply-To: 9fans@cse.psu.edu List-Id: Fans of the OS Plan 9 from Bell Labs <9fans.cse.psu.edu> List-Archive: Date: Mon, 6 Jan 2003 10:18:19 GMT Hi Roman, > Of course, good old: > > if ((a = do_it()) == BadThingHappened) > return TellEmAboutIt; > > works, but costs a little bit too much when clarity is needed. > Especially when a "transaction" like pattern is needed ( e.g. I need > to to have o1 = f1(); o2 = f2(); o3 = f3(); but if any of f* fails, I > have to destroy what I've got so far ). A common way of doing this is using goto. failed = 1; if ((res1 = lock(A) == 0) { goto releaseA; } if ((res2 = lock(B) == 0) { goto releaseB; } if ((res3 = lock(C) == 0) { goto releaseC; } foo(res1, res2, res3); failed = 0; releaseC: release(C); releaseB: release(B); releaseA: release(A); return failed; Cheers, -- Ralph Corderoy. http://inputplus.co.uk/ralph/ http://troff.org/ --upas-jdeeuxwxxiwphgjsnbqyjlepxe--