resource A() write("resource A is alive") final write("resource A has (been) terminated") end final end A resource B() write("resource B is alive") end B resource test_final_blocks() import A, B write("main resource is alive") var N : int := 1; getarg(1, N) var cA : cap A, cB : cap B cA := create A(); cB := create B() write("main resource has created resources A and B") if N = 1 -> write("normal termination") [] N = 2 -> write("stop"); stop [] N = 3 -> write("stop(1)"); stop(1) [] N = 4 -> write("destroy...") destroy(cA); destroy(cB) write("destroyed") fi final write("main resource has (been) terminated") end final end test_final_blocks /* ............... Example compile and run(s) % sr -o test_final_blocks test_final_blocks.sr % ./test_final_blocks 1 main resource is alive resource A is alive resource B is alive main resource has created resources A and B normal termination main resource has (been) terminated % ./test_final_blocks 2 main resource is alive resource A is alive resource B is alive main resource has created resources A and B stop main resource has (been) terminated % ./test_final_blocks 3 main resource is alive resource A is alive resource B is alive main resource has created resources A and B stop(1) % ./test_final_blocks 4 main resource is alive resource A is alive resource B is alive main resource has created resources A and B destroy... resource A has (been) terminated destroyed main resource has (been) terminated */