10-14-2009 03:05 PM
10-16-2009 11:54 AM
10-16-2009 01:13 PM - edited 10-16-2009 01:17 PM
From an architecture and design point of view I prefer to have one portion of the system responsible for cleaning up resources. If resources are cleaned up in multiple places it can be easy to miss cleaning up things properly. In the example that I posted it was possible for both the event loop or the state machine to cause the application to exit. To keep things in sync and ensure the application exits cleanly it is necessary for the two loops to both be able to inform the other that they are exiting. If only one of your tasks, say the event structure, can trigger an exit of the application then you don't need to generate the exit event back to the event structure. So, it depends on your specific application as to whether it is needed or not. If however any task other than the event task (the one containing the event structure) can cause the system to exit you must generate a use event to allow the event task to exit. If not you will be sitting there waiting for the user to hit the exit button.
Most of my applications generally have an initialization block that occurs before I enter the event task or the state machine as well as an exit block that does most of the cleanup. The initialization block is used to read data from config files, configure the custom menus, create specific system queues, etc. The exit block will save configuration data to a file if necessary, release system resources such as queues and perform any other tasks necessary to clean up. The over simply example I posted doesn't include these two additional blocks of code.
10-16-2009 02:56 PM