A programming example, restartSpawn, illustrates many of the function calls covered in this chapter and previous chapters. The example is provided as a framework illustration of the restart mechanism and the use of persistent memory. Parts of the example could be used as the basis of a more complex user application that incorporates hot restart.
The restartSpawn example uses two restartable actors, a parent actor, HR_parent.r and a child, HR_child.r which is spawned by the parent. Both actors should be compiled as supervisor actors. The source code for the two actors is provided in Appendix B, Example Application Code. The example can be summarized as follows:
The parent actor uses a set of control structures stored in persistent memory. It spawns the child actor using hrfexec() , then explicitly crashes, causing itself to be restarted by the system. It indirectly restarts the child actor each time it runs, through the call to hrfexec().
The child actor also uses a set of control structures stored in persistent memory. It executes a four-step loop which causes the following to be printed:
=========== Message =========== STEP 1 STEP 2 STEP 3 STEP 4 ======== End of message========
The message is printed independently of the number of times the parent actor crashes or the site is restarted.