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.
|