local thread = require("thread") local event = require("event") local cleanup_thread = thread.create(function() event.pull("interrupted") print("cleaning up resources") end) local main_thread = thread.create(function() print("main program") while true do io.write("input: ") io.read() end end) thread.waitForAny({cleanup_thread, main_thread}) os.exit(0) -- closes all remaining threads