1 / 34

Synchronous Process Cooperation

Explore the concept of process cooperation in object-oriented simulation using OOSimL, including master-slave synchronization and joint activities. Learn how to implement process cooperation through cooperation objects and synchronization mechanisms.

boltz
Download Presentation

Synchronous Process Cooperation

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

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

  3. Master-Slave Synchronization • 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. • When the period of cooperation ends, all processes continue with their independent activities. (C) J. M. Garrido

  4. Joint Activity For two processes to cooperate: • 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 • 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. Garrido

  5. 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 • The two processes will continue their own independent activities. (C) J. M. Garrido

  6. Cooperation Interval (C) J. M. Garrido

  7. Process Cooperation in OOSimL • OOSimL supports the cooperation of processes via cooperation objects. • 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. (C) J. M. Garrido

  8. Synchronization Mechanism • 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. • Every cooperation object has two hidden queues: • the slave queue • the master queue (C) J. M. Garrido

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

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

  11. Cooperation Statement in OOSimL • 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 master process that requests cooperation with a slave process, executes the cooperate statement. (C) J. M. Garrido

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

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

  14. Wait Statement • 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. (C) J. M. Garrido

  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. // wait for master process to cooperate wait for master in coopt_obj (C) J. M. Garrido

  16. Master Process Requests Cooperation • 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. • 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. Garrido

  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. • 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. (C) J. M. Garrido

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

  19. Length of Slave Queue • 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. assign length of slave queue < ref_var > to < var_name > (C) J. M. Garrido

  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. assign length of master queue < ref_var > to < var_name > (C) J. M. Garrido

  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 else // carry out some other activity endif (C) J. M. Garrido

  22. Cooperation with Several Slaves • 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. • 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. Garrido

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

  24. Example with Multiple Slaves(2) • 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 synchronization object, waitq_obj of class Waitq, is defined in the top class of the model. (C) J. M. Garrido

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

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

  27. Model with Synchronous Communication • There are several sender processes • There are several receiver processes • 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. (C) J. M. Garrido

  28. Synchronous Communication (C) J. M. Garrido

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

  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 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. (C) J. M. Garrido

  31. Results of a Simulation Run • 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 sender process • Channel utilization (C) J. M. Garrido

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

  33. Paging Disk • 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. • 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. Garrido

  34. Model Design • 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 disk continuously scans the sectors for requests. (C) J. M. Garrido

More Related