10.1 Project Overview

Team-FLY

This chapter's project develops an implementation of multiple timers in terms of a single operating system timer. The project consists of five semi-independent modules. Three of these are created as objects with internal static data; the other two are standalone programs designed for driving the timers and for debugging output. Figure 10.1 shows the five modules and their relationships. A dashed arrow indicates communication through a pipe. A solid arrow signifies that a function in the source module calls a function in the target module.

Figure 10.1. The five timer modules to be created in this project.

graphics/10fig01.gif

Standard output of the testtime program is fed into standard input of the timermain program. The timermain program calls only functions in virtualtimers . The virtualtimers object calls functions in hardwaretimer and show . The show object, which is only for debugging, calls functions in virtualtimers .

The project design has two layers ”a "hardware" level ( hardwaretimer ) and a virtual timer level ( virtualtimers ). The hardwaretimer layer encapsulates a single operating system timer that generates a signal when it expires. The underlying timer object can be either a POSIX:XSI timer or a POSIX:TMR timer. While not truly a hardware timer, it is treated as such. The object provides interface functions that hide the underlying timer from outside users. In theory, if the program has access to a real hardware timer, the underlying object can be this timer and the interface remains the same. The interface functions manipulate a single timer that generates a signal when it expires .

The virtualtimers object provides the core facilities for creating and manipulating multiple, low-overhead, application-level software timers. The virtualtimers object calls functions in the hardwaretimer to implement these software timers. The virtualtimers object also calls functions in the show object for logging and debugging.

The show object contains functions to display a running log of the timer operations during debugging. The show object calls functions from virtualtimers to obtain status information about the timers.

Each of the objects has a header file with the same name and a .h extension that contains prototypes for the functions accessible from outside the module. Any program that calls functions from one of these modules should include its corresponding .h file.

Two main programs are used for testing the timer objects. The first one, timermain , receives input from standard input and calls functions in the virtualtimers object. The timermain program might, for example, start a timer to expire after a given interval when it receives appropriate input. The timermain program calls only functions in the virtualtimers object.

It is critical to the debugging process that experiments producing incorrect results be precisely repeatable. Then, when a bug is detected , the programmer can fix the code and repeat the same experiment with the modified code. Experiments that rely on the timing of keyboard input are almost impossible to repeat. To solve this problem, the testtime program supplies input data through a pipe to timermain at precisely timed intervals. The testtime program reads lines from standard input and interprets the first integer on the line as a delay time. After waiting for this amount of time, testtime sends the rest of the input line to standard output. The testtime program then reads its next input line and continues.

This project chapter describes the implementation of virtual timers in stages. Section 10.2 introduces the data structures and gives examples of setting a single timer. Section 10.3 introduces the three objects and specifies how to handle the setting of a single timer with POSIX:XSI timers. Section 10.4 handles multiple active timers. Section 10.5 discusses some of the race conditions that can occur with multiple timers and ways to avoid them, and Section 10.6 discusses advanced timer issues in terms of POSIX:TMR timers. Section 10.7 introduces a simple timer application.

Team-FLY


Unix Systems Programming
UNIX Systems Programming: Communication, Concurrency and Threads
ISBN: 0130424110
EAN: 2147483647
Year: 2003
Pages: 274

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net