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.

3. Multi-Threaded Programming<br />

RTEvent subclasses freely modify both the timestamp and owner attributes.<br />

For instance, owner can be set to null, and the timestamp can be modified<br />

according to an improved estimation of a sampled input data value. The owner<br />

does not need to be a thread object, which is useful when, e.g., regulator<br />

objects in a control system are driven by some external thread; the eventemitting<br />

(but passive from a Java point of view) control block can still be the<br />

registered owner 5 of the object.<br />

The owner attribute is declared volatile to permit thread-safe access event<br />

from methods not being synchronized. Both source (from java.util.EventObject)<br />

and owner are declared transient since those attributes have no meaning outside<br />

the program (JVM) where they were created. Instead, for instance when<br />

serialized to a stream of bytes and sent over a network, they both get the<br />

value null.<br />

Real-Time Event Buffers – RTEventBuffer<br />

The class RTEventBuffer 6 is designed to accomplish message-based communication<br />

with buffering and using RTEvent objects as messages. To avoid confusion<br />

with other types of buffers in other Java packages or in operating systems,<br />

the following should be clear:<br />

1. Traditionally, demands on flexibility have been modest for real-time and<br />

embedded systems, and programming (in C) without support for object<br />

orientation has been standard. Messages for communication are then in<br />

most cases statically defined by some struct type. The size of the message<br />

can then be obtained by calling sizeof, no additional subclasses are<br />

available (or will be available during runtime), the data is not subject to<br />

relocation by some memory manager (GC), and therefore the message<br />

can be handled and copied as a sequence of bytes. With some restrictions,<br />

the same holds for programming in C++. A message can then<br />

be referred to by a pointer to the memory location, but to improve robustness<br />

for large complex systems the message data is normally copied<br />

for transfer to some other part of the software. The reason is that manual<br />

memory management in terms of programming rules and so called<br />

reference counting does not scale up very well.<br />

For multi-threaded programming in Java, we do not know the object<br />

size or where the object is stored in memory, and we do not have to<br />

5 The concept of ownership is taken from the OSE operating system from ENEA.se<br />

6 This buffer and the event class RTEvent are part of the se.lth.cs.realtime.event package.<br />

Like for the se.lth.cs.realtime.semaphore package, the classes as presented in this chapter are<br />

part of the Lund Java-based Real-Time (LJRT) library that in more detail will be the<br />

topic of the next chapter. The classes introduced in this chapter add basic utilities for<br />

concurrent programming, without changing the model of Java threads and without adding<br />

real-time support. These classes are straightforward to use on any Java platform, whereas<br />

the complete LJRT library adds more fundamental features.<br />

90 2012-08-29 16:05

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

Saved successfully!

Ooh no, something went wrong!