Presentation is loading. Please wait.

Presentation is loading. Please wait.

Synchronous Process Cooperation Object Oriented Simulation with OOSimL Chapter 26 (C) J. M. Garrido1.

Similar presentations


Presentation on theme: "Synchronous Process Cooperation Object Oriented Simulation with OOSimL Chapter 26 (C) J. M. Garrido1."— Presentation transcript:

1 Synchronous Process Cooperation Object Oriented Simulation with OOSimL Chapter 26 (C) J. M. Garrido1

2 Process Cooperation Needed when two or more processes are to carry out a joint activity for a finite interval. Needed when two or more processes are to carry out a joint activity for a finite interval. Used to model direct cooperation among processes Used to model direct cooperation among processes In both cases, the simultaneous participation of the processes involved is required. In both cases, the simultaneous participation of the processes involved is required. (C) J. M. Garrido2

3 Master-Slave Synchronization One process is chosen as the master. This is the dominant process during the cooperation period. One process is chosen as the master. This is the dominant process during the cooperation period. The other processes are the slaves. These are modeled as dormant participants during the period of cooperation. The other processes are the slaves. These are modeled as dormant participants during the period of cooperation. When the period of cooperation ends, all processes continue with their independent activities. When the period of cooperation ends, all processes continue with their independent activities. (C) J. M. Garrido3

4 Joint Activity For two processes to cooperate: The master process requests a cooperation with a slave process while executing some operation. The master process requests a cooperation with a slave process while executing some operation. The slave process requests a cooperation with a master process while executing some operation The slave process requests a cooperation with a master process while executing some operation When the slave process is not available, the master process has to wait and is suspended until a slave process becomes available When the slave process is not available, the master process has to wait and is suspended until a slave process becomes available (C) J. M. Garrido4

5 Cooperation Interval When the interaction starts, the slave process is suspended until the end of the cooperation interval. When the interaction starts, the slave process is suspended until the end of the cooperation interval. After the cooperation interval, the master process then reactivates the slave process After the cooperation interval, the master process then reactivates the slave process The two processes will continue their own independent activities. The two processes will continue their own independent activities. (C) J. M. Garrido5

6 Cooperation Interval (C) J. M. Garrido6

7 Process Cooperation in OOSimL OOSimL supports the cooperation of processes via cooperation objects. OOSimL supports the cooperation of processes via cooperation objects. These objects implement a synchronization mechanism for the processes to cooperate. These objects implement a synchronization mechanism for the processes to cooperate. This mechanism allows one or more processes to dominate and be treated as master processes; the other processes are treated as slave processes. This mechanism allows one or more processes to dominate and be treated as master processes; the other processes are treated as slave processes. (C) J. M. Garrido7

8 Synchronization Mechanism The synchronization mechanism used for the process cooperation is provided by objects of class Waitq, known as cooperation objects. The synchronization mechanism used for the process cooperation is provided by objects of class Waitq, known as cooperation objects. These objects support the cooperation of multiple slave processes and multiple master processes. These objects support the cooperation of multiple slave processes and multiple master processes. Every cooperation object has two hidden queues: Every cooperation object has two hidden queues: the slave queue the slave queue the master queue the master queue (C) J. M. Garrido8

9 Master - Slave Interaction (C) J. M. Garrido9

10 Synchronized Wait in the Cooperation When the master process requests cooperation, and there is no slave process available, the master process is suspended and placed on a master queue. When the master process requests cooperation, and there is no slave process available, the master process is suspended and placed on a master queue. When a slave process requests cooperation, and the master is not available, the slave process is suspended and placed on a slave queue. When a slave process requests cooperation, and the master is not available, the slave process is suspended and placed on a slave queue. (C) J. M. Garrido10

11 Cooperation Statement in OOSimL Processes initiate the cooperation by using the facilities provided by the cooperating object of class Waitq Processes initiate the cooperation by using the facilities provided by the cooperating object of class Waitq A slave process that requests cooperation with a master process, executes the wait statement. A slave process that requests cooperation with a master process, executes the wait statement. A master process that requests cooperation with a slave process, executes the cooperate statement. A master process that requests cooperation with a slave process, executes the cooperate statement. (C) J. M. Garrido11

12 Master-Slave Cooperation (C) J. M. Garrido12

13 Objects of Class Waitq Creating and declaring an object of class Waitq : define coop_obj of class Waitq create coop_obj of class Waitq using “M-S cooperation”,17 … // processes request cooperation (C) J. M. Garrido13

14 Wait Statement This allows a slave process to cooperate with a master process, when there is a master process available. This allows a slave process to cooperate with a master process, when there is a master process available. This statement places current process in the slave queue of the cooperation object and passivates (suspends) to wait for a master process. This statement places current process in the slave queue of the cooperation object and passivates (suspends) to wait for a master process. (C) J. M. Garrido14

15 Slave Process Requests Cooperation In the following lines of code allows a slave process waits for a master process to cooperate using the cooperation object coopt_obj. In the following lines of code allows a slave process waits for a master process to cooperate using the cooperation object coopt_obj. // wait for master process to cooperate wait for master in coopt_obj (C) J. M. Garrido15

16 Master Process Requests Cooperation A master process waits to cooperate with a slave process. A master process waits to cooperate with a slave process. A slave process is retrieved from the slave queue of the cooperation object, if this queue is not empty. A slave process is retrieved from the slave queue of the cooperation object, if this queue is not empty. If there is no slave process available in the slave queue, the master process that executes this statement is suspended and placed in the master queue. If there is no slave process available in the slave queue, the master process that executes this statement is suspended and placed in the master queue. (C) J. M. Garrido16

17 Example of Master Process Requests Cooperation In the following lines of code a master process waits to cooperate with a slave process using the coopt_obj synchronization object. In the following lines of code a master process waits to cooperate with a slave process using the coopt_obj synchronization object. When the cooperation becomes possible, a slave process is removed from the slave queue, the master process continues executing normally. When the cooperation becomes possible, a slave process is removed from the slave queue, the master process continues executing normally. Otherwise, the process is suspended to wait for a slave process. Otherwise, the process is suspended to wait for a slave process. (C) J. M. Garrido17

18 Cooperate Statement define custobj of class Customer... cooperate with slave custobj of class Customer in coopt_obj // execute when a slave is found (C) J. M. Garrido18

19 Length of Slave Queue The assign length statement assigns the length (number of processes) in the slave queue to a specified variable. The assign length statement assigns the length (number of processes) in the slave queue to a specified variable. This value represents the number of slave processes waiting on the cooperation (synchronization) object. This value represents the number of slave processes waiting on the cooperation (synchronization) object. assign length of slave queue to to (C) J. M. Garrido19

20 Length of Master Queue The assign length statement gets the length of the master queue (i.e., the number of master processes waiting on the cooperation object), and assigns it to the specified variable. The assign length statement gets the length of the master queue (i.e., the number of master processes waiting on the cooperation object), and assigns it to the specified variable. assign length of master queue to to (C) J. M. Garrido20

21 Deciding to Cooperate A master process may decide not to cooperate if there are no slave processes in the slave queue: define num_slaves of type integer... assign length of slave queue coopt_obj to num_slaves If num_slaves > 0 then … // joint activity with slave process … // joint activity with slave processelse // carry out some other activity // carry out some other activityendif (C) J. M. Garrido21

22 Cooperation with Several Slaves A master process can cooperate in a joint activity with several slave objects. A master process can cooperate in a joint activity with several slave objects. The master process creates a separate queue to place the slave processes. The master process creates a separate queue to place the slave processes. For example, a master process that needs to cooperate with N slave processes defines and creates a queue to place each reference to slave process. For example, a master process that needs to cooperate with N slave processes defines and creates a queue to place each reference to slave process. (C) J. M. Garrido22

23 Example of Cooperating with Multiple Slaves set numslaves = 0 set numslaves = 0 create s_queue = of class Pqueue using create s_queue = of class Pqueue using "Slave queue"...... while numslaves < N do while numslaves < N do cooperate with slave slave_ref of class Slave cooperate with slave slave_ref of class Slave in waitq_obj in waitq_obj // enqueue into slave queue // enqueue into slave queue insert slave_ref into s_queue insert slave_ref into s_queue increment numslaves increment numslaves endwhile endwhile // // (C) J. M. Garrido23

24 Example with Multiple Slaves(2) At the end of the cooperation interval, the master process removes each slave process and reactivates it. At the end of the cooperation interval, the master process removes each slave process and reactivates it. The master process then performs its own activities. The master process then performs its own activities. The synchronization object, waitq_obj of class Waitq, is defined in the top class of the model. The synchronization object, waitq_obj of class Waitq, is defined in the top class of the model. (C) J. M. Garrido24

25 Reactivating the Slave Processes // carry out joint activity for // cooperation interval hold self for coop_int // now release slave processes for j = 0 to N-1 do remove slave_ref of class Slave from s_queue reactivate slave_ref now endfor (C) J. M. Garrido25

26 Case Studies that Use Process Cooperation Process communication model Process communication model The paging disk system The paging disk system (C) J. M. Garrido26

27 (C) J. M. Garrido27 Model with Synchronous Communication There are several sender processes There are several sender processes There are several receiver processes There are several receiver processes A channel connects a receiver process to a sender process. A channel connects a receiver process to a sender process. A sender process directly communicates to with a receiver process in order to transfer a message. A sender process directly communicates to with a receiver process in order to transfer a message.

28 Synchronous Communication (C) J. M. Garrido28

29 (C) J. M. Garrido29 Synchronous Communication Model The sender processes are objects of class Sender The sender processes are objects of class Sender The receiver processes are objects of class Receiver The receiver processes are objects of class Receiver The channels are passive objects of class Comchan that relates with class Waitq The channels are passive objects of class Comchan that relates with class Waitq There is a channel for each pair of sender and receiver There is a channel for each pair of sender and receiver

30 Model Implementation The simulation model consists of five pairs of sender and receiver processes and is implemented with five classes written with OOSimL. The simulation model consists of five pairs of sender and receiver processes and is implemented with five classes written with OOSimL. The source files are: Scomm.osl, Sender.osl, Receiver.osl, Comchan.osl, and Message.osl. The source files are: Scomm.osl, Sender.osl, Receiver.osl, Comchan.osl, and Message.osl. These source files are archived in the file scomm.jar, which also includes the output listings of a sample simulation run. These source files are archived in the file scomm.jar, which also includes the output listings of a sample simulation run. (C) J. M. Garrido30

31 (C) J. M. Garrido31 Results of a Simulation Run Trace that shows sequence of events: the times that a pair of processes communicate Trace that shows sequence of events: the times that a pair of processes communicate Total wait period for each receiver process Total wait period for each receiver process Total wait period for each sender process Total wait period for each sender process Channel utilization Channel utilization

32 (C) J. M. Garrido32 Synchronous Communication Between Two Processes

33 Paging Disk A page disk receives random requests from various processes. A page disk receives random requests from various processes. Each track of the disk is partitioned into NUM_SECTORS sectors that store one page each. Each track of the disk is partitioned into NUM_SECTORS sectors that store one page each. Requesting processes select a sector and then wait for the completion of the request. The paging disk rotates once every 17.5 msec. Requesting processes select a sector and then wait for the completion of the request. The paging disk rotates once every 17.5 msec. (C) J. M. Garrido33

34 Model Design The model defines an array of NUM_SECTOR objects of class Waitq. The model defines an array of NUM_SECTOR objects of class Waitq. The arrivals process generates randomly the sector number for the next arriving process, which requests cooperation with the disk. The arrivals process generates randomly the sector number for the next arriving process, which requests cooperation with the disk. The disk continuously scans the sectors for requests. The disk continuously scans the sectors for requests. (C) J. M. Garrido34


Download ppt "Synchronous Process Cooperation Object Oriented Simulation with OOSimL Chapter 26 (C) J. M. Garrido1."

Similar presentations


Ads by Google