RTC Website

Waiting for real-time computing

TX

Control of time is paramount to real-time computing. Rigorous control of time requires threads and interrupts, which are topics covered in the next chapter. However, in “soft” real-time applications with limited computing resources, a very simple technique can be sufficient: waiting. We have already used waiting in lab 3, where we had a wait() function that simply decrements a large integer to zero before returning:

void wait(void) {
  uint32_t i;
  i = 417000;           // a large integer
  while (i>0) {
    i--;                // ... decremented to zero
  }
}

The (real) run time of this function depends on the compiler and processor. However, even for a compiled version of this function, the real execution time can depend on the operating system’s scheduler and the presence of other tasks. In a soft real-time application, the variability and uncertainty may be tolerable, and the typical execution time can be estimated from the compiled code (part of lab 4).

While waiting does have limitations arising from the variability and uncertainty of the timing of a wait function, there is a further limitation that is inherent to waiting itself. Say that we would like task \(a\) to be completed at a regular time interval \(T\). One approach would be to perform task \(a\), wait \(d = T\), then perform \(a\) again. However, the time interval would be \(T\) plus the duration of \(a\), \(\Delta a\). If \(\Delta a\) is predictable, we could shorten our wait to \(d = T - \Delta a\). However, we would often like to complete tasks of varying duration at regular intervals of time. Clearly, even if we had high confidence in the duration of our wait, we would be unable to guarantee regularity of the task interval. We will observe precisely this limitation in lab 4, when we create a task that a user can introduce arbitrarily (by the pressing of a button). In chapter 5, we will learn techniques that can properly address this situation.

Online Resources for Section 4.6

No online resources.