Guardian Programmer's Guide

Table Of Contents
Fault-Tolerant Programming in C
Guardian Programmer’s Guide 421922-014
27 - 43
Primary and Backup Processing
Primary and Backup Processing
The original application program can now be restructured into the following three
functions:
Function primary_processing, which performs the primary process activities: it
does the work of the application and updates state information in the backup
process.
Function backup_processing, which performs the backup process activities: it
receives state information from the primary process and monitors the primary
process CPU. If a message indicating CPU failure or process termination is
received, the backup process takes over execution.
Function main, which is where execution of the active backup program begins.
Function main determines whether it is running as the primary process or the
backup process: if it is the primary process, it initializes the backup process and
calls primary_processing; if it is the backup process, it calls
backup_processing.
A separate function, is_backup_process, is written to determine whether the
program is running as the primary process or the backup process. main calls this
function at the beginning of its execution.
Function primary_processing
Function primary_processing does the work of the application (which, in this
example, is to execute an infinite loop that increments a counter). Within the innermost
loop, function update_backup is called to update the state information in the backup
process.
/*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*/
void primary_processing (void)
{
for (;;)
{
counter++;
printf ("Counter is %d\n", counter);
if (counter > 10000) counter = 0;
update_backup (counter);
}
}