Kaffe deadlock using Thread.sleep()

Sauro Puccini qsapu at hotpop.com
Mon Aug 2 10:32:44 PDT 1999


I have detected a sort of deadlock problem using a Thread.sleep() during
a timered Socket read; this problem happens randomly, but in my system
it's easy to reproduce in less than 30 secs. I am currently using the
Kaffe version 1.0b4 compiled with Cygwin32 under WinNT, and running the
following sample :

import java.net.*;
import java.io.*;

class Loop
{
    public static void main(String av[]) throws Exception {
  final int LOOP_MAX = 10000000;
  final int port = 45054;
  ServerSocket server = null;

  try {
   server = new ServerSocket(port);
  } catch (IOException e) { System.out.println(e); }

        Thread t = new Thread() {
            public void run() {
    try {
     Socket s = new Socket(InetAddress.getLocalHost(), port);
     BufferedOutputStream out = new
BufferedOutputStream(s.getOutputStream());
     byte btx[]= new byte[10];
     for (int i=0; i<LOOP_MAX; i++) {
      try {
       out.write(btx, 0, 10);
      } catch (IOException e) { System.out.println(e); }
      System.out.print("#");
      try {
       out.flush();
      } catch (IOException e) { System.out.println(e); }
//      System.out.print("$");
      try {
       Thread.sleep(30);
      } catch (Exception e) {}
//      System.out.print("%");
     }
     out.close();
    } catch (Exception e) { System.out.println("Failure " + e); }
      }
  };

  t.start();
        server.setSoTimeout(5000);
        Socket rsocket = null;
  try {
   rsocket = server.accept();
  } catch (InterruptedIOException e) { System.out.println(e); }
  BufferedInputStream in = new
BufferedInputStream(rsocket.getInputStream());

        rsocket.setSoTimeout(20);
  byte brx[]= new byte[10];

  for (int i=0; i<LOOP_MAX; i++) {
   int len=0;
   try {
//    System.out.print("^");
    len = in.read(brx, 0, 10);
   } catch (InterruptedIOException e) {}
   if (len > 0)
    System.out.print("@");
   else
    System.out.print(".");
  }
 }
}




More information about the kaffe mailing list