I have following class:
@locked = false
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
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,