Upload
jeffry-harrell
View
213
Download
1
Embed Size (px)
Citation preview
Using a simple Rendez-Vous mechanism in Java
João [email protected]
Motivation
Real time programs Cooperating threads sharing the
same context (data structures, IO devices, etc.)
Need for interaction
Interaction
Interaction primitives: Locks Semaphores
Structured interaction mechanisms:
Rendez-Vous (ADA) Monitors (Java)
Java Monitors Monitor: passive object providing
synchronized methods Dynamic model of Java multithreading
computation: Dynamic set of monitors Dynamic set of threads Threads interact indirectly through monitor
services calls. Direct interaction of threads was
suppressed for safety reasons (e.g. functions resume() and suspend() not supported after JDK 1.3)
ADA’s Rendez-Vous Common execution of a code section by
two threads (tasks) Asymmetric, “roles” of both tasks are
different: The client calls rendezvous (and needs “to
know” the partner) The server accepts rendezvous (and does
not need to know the client) Synchronous, the first task reaching the
rendezvous point waits for its partner
ADA’s Rendez-Vous Data of both “actors” of rendezvous can
be used within the execution Every transformation of tasks data can
be programmed (and atomically executed) as a rendezvous
Dynamic model of Ada multithreading computation: Set of tasks that interact directly using the
rendezvous mechanism
ADA’s Rendez-Vous - Server Example
Initialization of Entries
Beginning of task
Store first Item
ADA’s Rendez-Vous - Server Example
Select statement with two alternatives
ADA’s Rendez-Vous – Client Example
Create the Task
Acess as a normal variable
Using ADA’s Rendez-Vous in Java – Why? Allows “pure monitor” (i.e. server)
thread. More general model of parallel
(concurrent) computation. An easy way how to synchronize
two threads in a specified point of their execution and join data exchange/transformation.
Using ADA’s Rendez-Vous in Java – Why?
A way how to construct threads with “two faces”, i.e. part of their life they can act as clients and another part as servers
A way how to construct multiple-mode monitors, e.g. monitors that provides various sets of services within various stages of their life.
Implementing Rendez-Vous in Java - Keypoints
As simple as possible,no need to include all the facilities of the Ada rendezvous implementation
No need for any special JVM or pre-processor
Construct an object type whose instance can manage an entry synchronization (i.e. to every single entry should be assigned one synchronization object).
Implementing Rendez-Vous in Java - Keypoints Methods of a dedicated
synchronization object should be called only from the server side of rendezvous.
To call an entry from the client side should be as simple as the Java conventional public method call
It is necessary to implement a simple form of the Ada select statement
Implementing Rendez-Vous in Java – State Machine
Implementing Rendez-Vous in Java – Entry class
Implementing Rendez-Vous in Java – Entry class
Implementing Rendez-Vous in Java – Entry class
Using the Entry class
Uses Entry e1
Both use Entry e2
Code executed inside the Rendez Vous
Using the Entry class
here it accepts only entry_1() call
it accepts either entry_21() or entry_22() call
it can call entry of another server as well
Conclusion
Simple and easy to use Just one class needed Extends possibilities on how to
design Java multithreaded program architecture
Future work
Add EntrySet class Include all the possibilities of the
select statement: Boolean guards Delays else alternative
Web
Source code and examples: http://www.kiv.zcu.cz/~stracek/ppr/java/randez/
Email: [email protected]