Subject: master-slave synchronization pseudocode

From: Saleh Elmohamed <[email-masked]>
Date: Sat, 6 Nov 1999 22:27:56 -0500

Geoffrey,

Here is a rough sketch of the pseudocode I put together
after our conversation.
Let me know whether it is clear or all wrong. I'll need
to get this logic right before I do any kind of implementation.

An applet running on a Java-based collaborative system:
------------------------------------------------------
Master-Slave Mode.

How to synchronize actions between the master and slaves:

Let's assume the system (the three modes) is represented by three
processes: proc1 for master, proc2 for slaves present at the start of
session, and proc3 for later just-joined-in slave(s).

Here are how the processes might look like in pseudo-coded format:

 proc1()
  {
    encapsulated settings:
       action iterate = 0;
       action synch = {true, false}

    begin loop
   
      iterate++;
      inc time(10);      // if any of the slaves still get
                         // ahead of master, this time can
                         // be reduced further.
 
      do
       set action synch = true;
       send-slaves (iterate, synch);
       wait(5);
      enddo

      set action synch = false;

    continue loop;

  }
--------------------
 proc2(number n, action s)
  {
   encapsulated settings:
      action iterate = 0;
      action just-joined-in ={true, false};

   begin loop
     set action just-join-in = false;
     iterate++;
     receive-master (n, s);

     if(s)
      {
       barrier:
          if (n < iterate)
           {
             action reset;   // if slave got ahead of the master
                             // reset action and back off to the
                             // point of start???
             set action iterate = 0;
             while (iterate < n)
                iterate++;
           }
          else
           {
             continue;
             do {
                 iterate++
                } while(iterate < n);
           }
       end barrier;
      }
     else
       continue;
   end loop;
 }
-----------------
 proc3(number n, action s)
  {
   encapsulated settings:
      action iterate = 0;
      action just-joined-in {true, false};

   set action just-joined-in = true;

   send-master (just-joined-in);
 
   begin loop
     
     iterate++;
     receive-master(n, s);

     barrier
       if (not s)
         set action just-joined-in = false;
     end-barrier;

     set action just-joined-in = false;

   end loop;
 }