|< ... >||item|
|[ ... ]||optional|
|( ... ) *||0 or more times|
|( ... ) +||1 or more times|
- [ <main code> ]
- [ <exit code> ]
The OnExit statement can be used between the Begin and End statements in the Process or Function. When the Program, Process or Function is killed, the exit code starts. This can be easily used to free any memory used by the exiting process.
Loop frame; End
will cause Bennu to freeze, as frame(0); doesn't allow switching to another instance.
import "mod_proc" import "mod_say" Process proc1() Begin // Start the main code part of the process say("Proc created"); // Run indefinitely (or until killed) Loop frame; End OnExit // Start the exit code of the process say("Proc killed!"); End Function int func1() Begin // Start the main code part of the function say("Func created"); return 0; OnExit // Start the exit code of the function say("Func killed!"); End Process Main() Private int p; Begin // Start the main code part of the main process p = proc1(); // create new instance of proc1 func1(); say("Main is here"); OnExit // Start the exit code of the main process say("Main is killed"); signal(p,S_KILL); say("Main is at the end"); End
Resulting console messages:
Proc created Func created Func killed! Main is here Main is killed Main is at the end Proc killed!
A good use for this is the following:
Process ship() Begin graph = map_new(20,20,8); Loop frame; End OnExit map_unload(0,graph); End