scope(exit)

Derek Parnell derek at psych.ward
Wed May 10 18:57:35 PDT 2006


On Sat, 13 May 2006 10:16:11 +1000, MM <MM_member at pathlink.com> wrote:

> I've been reading through Exception Safe Programming page and I had a  
> question:
>
> why not:
> scope(exit) unlock(m);	
> lock(m);	
>
> iso the inverse?
> lock() might crash but might still have locked m
> Or is this stpd reasoning?
> unlocking m when it is not locked should not ba a problem or the  
> scope(exit)
> could check whether or not m is locked?

I prefer to think of the purpose of 'unlock' is to ensure that the  
resource is unlocked by the time the function completes. This is slightly  
different from saying the purpose of 'unlock' is to unlock the resource.  
Thus if it is already unlocked when it starts, all it does is return. The  
same goes for a file or database 'close' function.

-- 
Derek Parnell
Melbourne, Australia



More information about the Digitalmars-d mailing list