06.08.2013 Views

JAVA-BASED REAL-TIME PROGRAMMING

JAVA-BASED REAL-TIME PROGRAMMING

JAVA-BASED REAL-TIME PROGRAMMING

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

2. Fundamentals<br />

int x = 2;<br />

while (x>1) {<br />

if (x==10) x = 0;<br />

x++;<br />

};<br />

/* What is x now? */<br />

Figure 2.1: Code snippet illustrating sequential execution, trivial to any programmer<br />

but many beginners actually give the wrong answer 0.<br />

Even if computers today are computing quickly enough to do the computations<br />

required by a parallel environment (like our real world).<br />

So, when learning to program, we are first forced into the ‘narrow alley’ of<br />

sequential execution. Compare this with hardware design where each signal<br />

or information flow usually is taken care of by dedicated components ensuring<br />

continuous and timely operation. But for reasons of cost and flexibility, we<br />

cannot implement everything in hardware, so the problem that we are facing<br />

now is that the sequential software execution model does not fit the inherently<br />

parallel problems we want to solve. Even when solving parallel problems,<br />

however, some things are still sequential to their nature (like a sequence of<br />

control actions to be carried out in the correct order). Then, for such parts of<br />

the program, the sequential execution of software will be of great convenience.<br />

2.2 Our physical world is parallel<br />

The object oriented programming (OOP) paradigm, which we want to use<br />

for embedded programming, is based on creating software entities modelling<br />

our environment. Furthermore, since we aim at computer control of physical<br />

devices, some thoughts about the environment to be controlled may be<br />

appropriate 1 .<br />

As we all know, our physical world is inherently parallel. Mathematically,<br />

we need sets of coupled differential equations to describe it. Comparing such<br />

mathematical expressions with the expressions found in programming languages<br />

such as Java, they are not at all expressing the same thing. Basically,<br />

this is related to another beginners problem in programming; the notion of<br />

equality. When an mathematical expression states that x=y+2, that is an<br />

equality which should hold for whatever value x (or y) has. When we in a<br />

Java program write x=y+2, we instruct the computer to take the vale of y,<br />

add 2, and to store that in x. If we in Java write x==y+2, we test if the value<br />

of x equals y+2. The mathematical equality cannot be directly expressed in<br />

Java (or in any other widely used programming language like C, C++, etc.).<br />

Again, computers operate sequential from a programmers point of view.<br />

1 This section (1.2) aims at deeper understanding or wider perspectives, but can be<br />

skipped by the reader only caring about practical programming issues.<br />

18 2012-08-29 16:05

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

Saved successfully!

Ooh no, something went wrong!