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.
The se.lth.cs.realtime package<br />
4.7. Exercise 5 - Mailbox and lab 3 preparation<br />
The realtime package provides a message passing runtime system used by<br />
the classes above. All threads contain a mailbox attribute. Threads check<br />
their own mailboxes using doFetch/tryFetch (blocking/non-blocking) methods.<br />
They post messages to other threads using the putEvent method on the<br />
other thread.<br />
RTThread<br />
Superclass of all thread classes. Used for transactional threads. Note the<br />
mailbox attribute and the interrupt method.<br />
public abstract class RTThread implements Activity , RTEventListener ,<br />
RTEventSource {<br />
}<br />
/** The event input buffer. */<br />
protected volatile RTEventBuffer mailbox;<br />
/**<br />
* Put the time -stamped event in the input buffer of this thread. If the<br />
* buffer is full , the caller is blocked.<br />
*<br />
* @return null , but subclasses are free to return an event if desired to<br />
* inform about blocking or results.<br />
*/<br />
public RTEvent putEvent(RTEvent ev) {<br />
mailbox.doPost(ev);<br />
return null;<br />
}<br />
/**<br />
* Interrupts this thread. Thus an interruption -flag is set , which may<br />
* raise an InterruptedException in the interrupted thread; otherwise the<br />
* flag can be checked via interrupted or isInterrupted.<br />
*/<br />
public void interrupt() { ... }<br />
/**<br />
* Tests if the current thread has been interrupted. The interruption -flag<br />
* is reset.<br />
*<br />
* Note that interrupted is a static method , while<br />
* isInterrupted is called on this Thread instance.<br />
*<br />
* @return true if the current thread has been interrupted;<br />
* false otherwise.<br />
*/<br />
public static boolean interrupted() { ... }<br />
/**<br />
* Tests if this thread is alive. A thread is alive if it has been started<br />
* and has not yet died.<br />
*<br />
* @return true if this thread is alive; false otherwise.<br />
*/<br />
public final boolean isAlive() { ... }<br />
133