06.08.2013 Views

JAVA-BASED REAL-TIME PROGRAMMING

JAVA-BASED REAL-TIME PROGRAMMING

JAVA-BASED REAL-TIME PROGRAMMING

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

2. Fundamentals<br />

Definition: The correctness of a concurrent program does not only require<br />

each programmed sequence of computation to be correct, the correct result<br />

must also be obtained for all possible interleavings.<br />

In terms of the bank example this means that money should not be (virtually)<br />

lost or created due to the timing of transactions and computer operations.<br />

Even if that is an obvious requirement, it is actually a quite severe demand<br />

when it comes to verification of the correctness and finding any faults; the<br />

task we call test and debugging. Debugging an ordinary sequential program<br />

can be done by running the program with all possible sets of input data, and<br />

one set of input data gives the same result if the program is run again. For<br />

a concurrent program, however, the interleaving depends on external events<br />

triggering different sequences of scheduling and execution. With a concurrent<br />

program, we can usually not expect to obtain the same execution order<br />

twice; an input event occurring just a microsecond later may result in another<br />

interleaving which may course an incorrect program to crash. That in turn<br />

must not happen for a safety critical application. Hence, we may have severe<br />

requirements on correctness but complete testing is almost never possible.<br />

It is interesting to note that the definition of correctness does not say<br />

anything about time or timing, but timing is both the main reason for introducing<br />

concurrency and the key aspect for the behavior of an incorrect<br />

program. Considering the difficulties writing and testing concurrent software,<br />

our hope now is that we can find and follow certain rules for development of<br />

such software.<br />

2.5 Interrupts, pre-emption, and reentrance<br />

Just like we did not allow the user program to poll the inputs for possible<br />

events (which would be waste of computing power when no new event has<br />

arrived), the same applies to the scheduler or scheduling. The invocation of<br />

the scheduler and its implications for the software application deserve some<br />

comments.<br />

2.5.1 Obtaining the time base<br />

As mentioned, we resort to using hardware interrupts to trigger our software<br />

functions, even if the interrupt service routines as such are hidden inside the<br />

operating system and device drivers. Of course, we may have input signals<br />

which do not generate any interrupt, but then we read that value at certain<br />

times, usually periodically when the data is used for feedback control. Therefore,<br />

the scheduler should also be able to handle time requests, such as “sleep<br />

one second” which then should suspend execution for that activity during that<br />

period of time.<br />

Hence, our computer must be equipped with some kind of timer interrupt<br />

occurring periodically, thereby providing a time base for the software. Of<br />

26 2012-08-29 16:05

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!