Guardian Programmer's Guide

Table Of Contents
Fault-Tolerant Programming in C
Guardian Programmer’s Guide 421922-014
27 - 32
Active Backup Example 1
Active Backup Example 1
A simple example is now used to illustrate how to structure an active backup program.
The following application consists of a loop that increments a counter.
/*This function does the work of the application, which is
to increment a counter. To avoid overflow, the
application wraps around after 10,000 iterations*/
int main (void)
{
short counter;
for (;;)
{
counter++;
if (counter > 10000) counter = 0;
/*Code that uses the counter value would go here*/
}
}
The rest of this subsection shows the steps involved in creating an active backup
version of this program. The program is coded in a modular style, with the various
active backup activities written as separate functions. You can use this example as a
template for writing your own active backup applications.
To simplify the presentation, error conditions returned by C library routines and
Guardian procedures are not handled.
Figure 27-5 and Figure 27-6 show the functional flow for the primary and backup
processes, respectively. The names outside the boxes indicate user-written functions
that perform the activities.