You can do
with lock:
# lock is held
# lock released
with lock:
# lock is held again
Also Go's defer keyword, which is bound to the current function (defer until function returns).std::mem::forget is considered safe, as explained in its docs: https://doc.rust-lang.org/std/mem/fn.forget.html
For C++ and Rust there might not be a well defined scope since objects can be „moved“. Eg a method constructing an object can return it to the caller without the destructor being called.
``` (call-with-output-file some-file (lambda (out) (write 'hello out))) ```
scope(exit) foo(); // Call foo at the end of the scope
scope(success) foo(); //Call foo if all goes well
scope(failure) foo(); //Call foo if the wings fall off the plane.