[Shootout-list] Re: ring of processes

Isaac Gouy igouy2@yahoo.com
Mon, 1 Nov 2004 09:02:43 -0800 (PST)


> When your favorite language is added we will change 128
> to something that matches the relative performance of process 
> creation/message passing in the new language. 

Each language will send a different number of messages for the same
test?!

> 2. The first process will send (128*N)-1 messages to the second 
> process in the ring. The contents does not really matter, but should
> not be ''stop''.

The size of the message does not really matter?!

We have a workable test for process communication - chainmsg

public class chainmsg {
   static final int LENGTH = 1000;

   public static void main(String args[]) {
      int m = 1;
      if (args.length > 0) m = Integer.parseInt(args[0]);

      EndLink chainEnd = new EndLink(null, LENGTH * m);
      chainEnd.start();
      Link chain = chainEnd;
         
      for (int i=2; i<=LENGTH; i++){
         Link link = new Link(chain);             
         link.start();
         chain = link;
      }

      for (int i=0; i<m; i++) chain.put(0);  
   
      try { chainEnd.join(); } catch (InterruptedException e){} 
      System.out.println(chainEnd.count);
      System.exit(0);
   }
}


class Link extends Thread {
   Link next;
   int message = -1;
   boolean busy = false;
   
   Link(Link t){
      next = t;
   }

   public void run() { 
      for (;;) next.put(this.take());          
   }

   synchronized void put(int m) {
      while (busy)
         try { wait(); } catch (InterruptedException e){}   
      busy = true;
      message = m;
      notifyAll();

      while (message != -1)
         try { wait(); } catch (InterruptedException e){}  
      busy = false;
      notifyAll();            
   }

   synchronized int take() {
      while (message == -1)
         try { wait(); } catch (InterruptedException e){}  

      int m = message;
      message = -1;
      notifyAll();
      return m+1;             
   }
}


class EndLink extends Link {
   public int count = 0;
   private int finalcount;
   
   EndLink(Link t, int i){
      super(t);
      finalcount = i;
   }

   public void run() { 
      do 
         count += this.take(); 
      while (count < finalcount);       
   }
}



		
__________________________________
Do you Yahoo!?
Yahoo! Mail Address AutoComplete - You start. We finish.
http://promotions.yahoo.com/new_mail