JAVA-BASED REAL-TIME PROGRAMMING
JAVA-BASED REAL-TIME PROGRAMMING
JAVA-BASED REAL-TIME PROGRAMMING
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
2.4. Concurrency<br />
in functions like run. But before we learn how to design and program such<br />
functions, there are some things we should observe.<br />
2.4.3 Programming of parallel sequences<br />
The functionality we are aiming at resembles that of an operating system;<br />
several programs that run at the same time should be scheduled to share<br />
the CPU in order to let each of the programs behave timely. However, the<br />
concurrency of complete programs is another topic handled later in this book.<br />
For now, we assume that the concurrency stems from the parallelism of a<br />
single application or program. It is then a big advantage that separately<br />
programmed concurrent activities can share and operate on the same data<br />
structures or objects. Otherwise, we would need additional files, pipes, sockets,<br />
etc. to exchange data, and that would be slower and much more work to<br />
program. Furthermore, assume that our program containing the concurrently<br />
executing activities is the only program we are running. (We cannot make<br />
assumptions about other programs anyway, and when we load our software<br />
into an embedded computer this assumption is normally fulfilled.)<br />
When an ordinary sequential program executes, from entering the main<br />
program until the final end, there is at each time one specific point of execution.<br />
We refer to that point in terms of a program counter (PC). We have<br />
so far realized that we require the program to be concurrently ongoing, typically<br />
executing in several objects simultaneously. That is, the program has<br />
to switch between its concurrent activities in such a way that, with the time<br />
scale of the application at hand, it appears (to the user and to the controlled<br />
system) to run in parallel (on different CPUs). To achieve this, the run-time<br />
system has to provide:<br />
1. A function for creating a new concurrently executing activity, i.e., an<br />
additional PC and the states comprising the context associated with the<br />
point of execution.<br />
2. A scheduler that provides sharing of the CPU in common by interleaving<br />
the executions. This should be without requiring the source code to be<br />
cluttered with statements not modeling the task to be performed.<br />
3. When concurrent activities share the same data or is dependent on each<br />
others computational results, there must be some means of synchronization<br />
and communication.<br />
The need for a scheduler is related to the obligations of the operating system<br />
for running complete programs, but as mentioned, here we are concerned with<br />
the parallel behavior of one program. Assuming that our system is equipped<br />
with such a scheduler, interlacing the different points of execution, we may<br />
define the following requirement for a concurrent program to be correct:<br />
25