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.
···
–
Wejn <lists+rubytalk(at)box.cz>
(svamberk.net’s Linux section, fi.muni.cz student, linuxfan)
Bored? Want hours of entertainment? <<<
Just set the initdefault to 6! <<<
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.
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.