From: Pierre Brengard Date: 2002-07-12T20:01:47+09:00 Subject: Re: Destructors in Ruby what about using Mutex ? Wejn wrote: > Hi all, > I have following class: > > class Foo > def initialize > @locked = false > end > > def lock > return if @locked > # Set up exclusive-write lock > @locked = true > end > > def do_something > raise RuntimeError, "Not locked" unless @locked > # Do something if locked > end > > def unlock > return unless @locked > # Free that lock > @locked = false > end > end > > Is there any way I can ensure that 'unlock' will be called at the end of > instance lifetime (before GC will purge it out of mem)? I need this > feature because I can't leave the external resource locked and I can't > trust to other code to release (unlock) it correctly. > > Thanks in advance, > W.