Example Java classes used in CS237
- Setting up a a process as a threaded object by,
- Extending class Thread -
B1, B2
- Implementing the runnable interface -
B3, B4
- Busy waiting attempts to solve the mutual exclusion problem
adapted from Ben-Ari's presentations
[ B-A82 ,
B-A90 ]
- mutex0 - no synchronisation whatever.
- mutex1 - using a `turn' variable to ensure mutual exclusion, and a
while (true) {} loop for being busy.
- mutex1a - using a `turn' variable to
ensure mutual exclusion, and Java's yield method
from class Thread for being busy.
- mutex2 - flag of intention approach; this attempt is unsafe.
- mutex3 - flag of intention approach; this is overly safe.
- mutex4 - flag of intention approach; now we give way when we
cannot get in.
- mutex5 - Dekker's algorithm.
- Synchronized blocks and methods
- mutex7 - synchronized block solution to the MEP.
- server1 - synchronized block example.
- server2 - synchronized method example.
- Semaphores
- semaphore - implementation of a general seemaphore
using Java's wait and notify.
- semaphore1 - another implementation of a general semaphore
- semaphore2 - implementation of a general semaphore using Java's
while (condition) {...wait()...}
loop to suspended a process invoking a P().
using java's wait and Notify.
- mutex6 - solution to the mutual exclusion problem using semaphores,
the semaphore implementation used is semaphore1.
- mutex6a - solution to the mutual exclusion problem using semaphores,
the semaphore implementation used is semaphore2.
The dinining philosophers problem
- dpp1 - semaphore version, but is not deadlock free.
- dpp2 - semaphore version, uses a semaphore MAX to avoid deadlock.
- dpp3 - semaphore version, uses a synchronized block to avoid deadlock.
Asynchronous message passing
- buffer - semaphore implementation of a bounded buffer.
- pc - example producer-consumer problem.
Readers and writers problem
- rw1 - solution using semaphores mutex and writing.
- rw2 - mutex now replaced by a synchronized block.
Synchronised message passing
In these examples a process sender has to send 50 messages to process
receiver such that each message is passed synchronously.

- handshake1 -
class with methods send and receive
defined using class semaphore2.
- handshake2 -
class with synchronised methods send and receive
defined using Java's
while (condition) {...wait()...} suspension loop.
- Add SR's st for peeking at messages to handshake2 (job to do).
- sender - sender process uses class handshake2
to communicate with a receiver process.
- receiver - receiver process uses class
handshake2 to communicate with the sender process.
- MessageTest1 - test program using class
handshake2 to pass 50 messages synchronoulsy from a sender process
to a receiver process.
Rendezvous (still to do)
Critical regions
Data flow (still to do)
inspired by the Lucid data flow programming language of Ashcroft and Wadge
[ WA85 ].