Path: csiph.com!usenet.pasdenom.info!news.albasani.net!news.mixmin.net!eweka.nl!hq-usenetpeers.eweka.nl!ecngs!feeder.ecngs.de!Xl.tags.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!local2.nntp.ams.giganews.com!nntp.brightview.co.uk!news.brightview.co.uk.POSTED!not-for-mail NNTP-Posting-Date: Fri, 22 Jun 2012 11:18:46 -0500 From: Gareth Owen Newsgroups: comp.lang.c Subject: Re: Design decisions References: <87a9zwb8xs.fsf@gmail.com> Date: Fri, 22 Jun 2012 17:18:47 +0100 Message-ID: <87sjdn8gm0.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:0UboKs+PGqTxCdxs8Z8TXvdVgKM= MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Lines: 19 X-Usenet-Provider: http://www.giganews.com X-Trace: sv3-IWYmi9v6wT5lO7KtXCJjIS4M9vzC0NSRMQ0Mz1S19BrpDGYghgcxeLUqiQEKqCsN2gUOxRwLj93ZJeI!xwatanHiL5/6npBS+lj+wjeIizcWE/0yfEQaG4yqxB6fV9a8rKiIsZutejJLyLXp5ezM X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 1871 Xref: csiph.com comp.lang.c:22545 jacob navia writes: > Very easy. Just use a pushdown stack. Each time you acquire a > mutex lock you push it in the stack, each time you release it you pop it. Which is, of course, precisely C++ exceptions give you for (almost) free. > If an exception occurs, you pop the whole mutex stack. Which is fine if *all* your resources are mutexes. Again, if you have nested resources that must be acquired and released in precisely the correct order, everything gets a little more complicated. I guess you just have to use a double stack of function pointers / data pointers that get called in reverse order? > This would require just a few lines more of code. Any chance of an example?