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.

1. Introduction<br />

control may be delayed due to the dynamics of the other part. Furthermore,<br />

assume it should be simple (no reprogramming, only altering a data value) to<br />

change the sampling period of the temperature control.<br />

A better way is to write two pieces of program, for instance two classes that<br />

handle the two control tasks. How should that be done, and what requirements<br />

does that put on the programming and run-time system?<br />

Example 2: Bank-account transactions<br />

A familiar example of concurrently occurring actions on the same data item,<br />

is bank account transactions. Assume that there are two transactions that<br />

are to be carried out at about the same time. One of them, which we call<br />

A, consists of taking out $1000 from the account via a money machine. The<br />

other transaction, which we call B, is to add a salary of $10000 to the account.<br />

Depending on the actual timing, and depending on how the bank computer<br />

performs the transactions, we obtain different cases. If one transaction is<br />

performed before the other, we have one of the two cases shown in Figure 1.2.<br />

Each sequence of operations expresses the way the computer at the bank<br />

performs the requested transactions.<br />

According to proper software engineering practice, the two sequences are<br />

preferably expressed separately as described in the previous example. Furthermore,<br />

assume that the run-time system of our computer is capable of<br />

interleaving the two sequences in such a way that they appear to be done simultaneously.<br />

Since the interleaving is not specified in the individual programs<br />

as shown in the figure, it could result in any order of operations depending on<br />

the underlying system, and it could possibly be different from time to time.<br />

For instance, we may for the above transactions obtain interleavings according<br />

to Figure 1.3. Even if automatic interleaving of code sequences often is desired<br />

to handle several tasks in parallel, we see that we must be able to specify a<br />

sequence of operations to be performed without being interrupted by other<br />

sequences manipulating the same (shared) data. We shall learn several ways<br />

to solve this type of problem.<br />

// Case 1: Withdraw first<br />

A: Read 5000<br />

A: Amount = 5000 - 1000<br />

A: Write 4000<br />

B: Read 4000<br />

B: Amount = 4000 + 10000<br />

B: Write 14000<br />

// Case 2: Salary first<br />

B: Read 5000<br />

B: Amount = 5000 + 10000<br />

B: Write 15000<br />

A: Read 15000<br />

A: Amount = 15000 - 1000<br />

A: Write 14000<br />

Figure 1.2: Two bank account transactions done in two different orders. In<br />

both cases, the original amount was 5000 and the resulting amount is 14000<br />

as expected.<br />

14 2012-08-29 16:05

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

Saved successfully!

Ooh no, something went wrong!