JAVA-BASED REAL-TIME PROGRAMMING
JAVA-BASED REAL-TIME PROGRAMMING
JAVA-BASED REAL-TIME PROGRAMMING
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
3. Multi-Threaded Programming<br />
T1 mutex<br />
T2<br />
take take<br />
give<br />
give<br />
Figure 3.3: Sequence diagram showing two threads (T1 and T2) using a<br />
semaphore (mutex) for mutually exclusive access to some shared resource.<br />
In this case T1 happens to be the first to take the semaphore, resulting in<br />
T2 being blocked while T1 is in the critical section.<br />
mutex semaphore class, in which the take saves a reference to the currently<br />
executing thread (entering the critical section) and give checks that the caller<br />
is the same thread (leaving the critical section). Of course, one could imagine<br />
situations when the unlocking should be taken care of by another thread, just<br />
like a person locking a room could hand over the key o someone else that takes<br />
care of unlocking, but that is simply not permitted.<br />
Another benefit with distinguishing mutex semaphores from signaling ones<br />
is to inform the run-time system (including the scheduler of thread execution)<br />
that a call of take means locking a resource. That information can then be<br />
used (as we will see in Chapter 4) to improve response times.<br />
Rendezvous<br />
During the 1980:s there was a development towards a uniform synchronization<br />
primitive called rendezvous, which is French and means something like ’getting<br />
together at a meeting point’. It was in the Ada language standard in 1983<br />
that rendezvous was defined as the general synchronization mechanism. With<br />
language support for Tasks (active objects with built-in mutual exclusion)<br />
that communicate synchronously (i.e., using rendezvous), the intention was<br />
to force concurrent real-time software to be written in such a way that is was<br />
ready for distribution over several processors. However, some applications are<br />
more complicated to implement using rendezvous, or requires more concurrent<br />
activities (thereby also decreasing performance) than if other mechanisms are<br />
used. Therefore, and perhaps due to programmer preferences, the more recent<br />
Ada95 standard also supports synchronized methods similar to what we have<br />
60 2012-08-29 16:05