Advanced Modelling Features

WaitQueue

Master-Slave Process Cooperation

   
 

common task

Process cooperation is a very common problem in the field of computer science. The question to be solved is how to synchronise two processes so that they can work together on the same task. Usually, this is done in an asymmetric way with one process acting as the active master and the other process as the passive slave. After completing their common task, both processes continue with their separate life cycles.

  

DESMO-J provides the WaitQueue and ProcessCoop classes as a comfortable means to model asymmetric master-slave process synchronisations.

A desmoj.core.advancedModellingFeatures.WaitQueue<M extends SimProcess, S extends SimProcess> (API) object maintains two internal queues, one for processes cooperating as masters (the M queue) and one for processes cooperating as slaves (the S queue).

A process of type S acting as a slave calls the waitOnCoop() method of the WaitQueue object. The WaitQueue automatically inserts the process into the internal slave queue and passivates it. If there is already a master process waiting, their cooperation will be initiated.

A process of type M acting as a master signals its request for cooperation to the WaitQueue<M,S> object by calling the cooperate(ProcessCoop<M,S> coop) method. The WaitQueue<M,S> looks for a slave in the slave queue and, if there is one available, removes it from the queue and starts the cooperation. Otherwise, the master process will be automatically enqueued and passivated.

wait queue object

After cooperation is completed, control returns to the master process and the slave process is scheduled for re-activation right after the master.

cooperation  object

Let us take a look at an example which applies this synchronisation construct.



   
  http://desmoj.sourceforge.net/tutorial/advanced/waitqueue0.html