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.
3. Multi-Threaded Programming<br />
mutex<br />
Track for loading<br />
Track for unloading (incoming trains mutual exclusive)<br />
Buffer signal<br />
Industrial track (resources handled along the line)<br />
Wagon to wagon zone<br />
entry exit<br />
Figure 3.5: Railroad tracks seen from above, illustrating semaphore usage.<br />
The name of the semaphores refer to the semaphore figures earlier in this<br />
section. The Buffer is a place for storage, permitting one train to unload and<br />
continue before the next train arrives for loading. In the lower right zone<br />
there is no such buffer (or intermediate passive object) so loading has to be<br />
done directly from one train to another, which corresponds to the synchronous<br />
mechanism of rendezvous.<br />
no such intermediate storage; both trains have to be there to permit items<br />
to be transferred from one train to another, which corresponds to rendezvous<br />
implemented by the semaphores entry and exit. In more detail, trains on the<br />
industrial track have access to resources along the track but when reaching<br />
the transfer zone it gets blocked until the other train is on the adjacent track.<br />
The train entering the zone for unloading (coming from the track for loading)<br />
also has to wait until the other train is there.<br />
Hence, in terms of software again, with the use of rendezvous you know that<br />
the passed data is actually in use by the other thread when the calling thread<br />
continues execution, whereas using ordinary method calls for data transfer<br />
(even if the method belongs to an active object) the executing thread using<br />
the provided data can be unaffected (for some time after the call).<br />
Disadvantages<br />
When using semaphores, one should also be aware of the drawbacks (both in<br />
general and compared to other techniques introduced later). If semaphores<br />
are inlined in the code wherever mutual exclusion is to be accomplished, it<br />
gets hard to read and maintain the program. If it is not clear where the critical<br />
sections actually are, the risk for shared data not being locked increases.<br />
Another case is statements like if, throw, and return unintentionally results in<br />
a resource being left in a locked state, and the entire application gets locked<br />
up or does not work anymore. A first good rule therefore is to place critical<br />
sections as methods in separate classes.<br />
62 2012-08-29 16:05