This is the mail archive of the java-prs@sourceware.cygnus.com mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

gcj/13: Blocking I/O calls cause other threads to lock



>Number:         13
>Category:       gcj
>Synopsis:       Blocking I/O calls cause other threads to lock
>Confidential:   no
>Severity:       critical
>Priority:       high
>Responsible:    apbianco
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Jul 14 00:00:02 PDT 1999
>Closed-Date:
>Last-Modified:
>Originator:     Bryce McKinlay
>Release:        libgcj 99-07-13 snapshot
>Organization:
>Environment:
Redhat Linux 6.0, kernel 2.2.7, glibc 2.1.1-6
>Description:
If a thread enters a blocking IO call [anything that 
eventually calls FileDescription.read(), for example], and
that call blocks, ALL other threads are prevented from 
executing properly (!). Among other things, new threads do
not get created until the blocking read() call returns. 
>How-To-Repeat:
This code demonstrates the problem. If things are working 
right, it should print "this is okay" and exit. If not, it
will just hang until a key is pressed because the second
thread will not be created until the first unblocks. 

(Sorry that this example is not more concise!)

import java.io.*;

public class BlockThread implements Runnable
{
  private InputStream is;
  
  public static void main(String args[])
  {
    try
      {
	BlockThread t = new BlockThread( System.in );
	// give the BlockThread lots of time to start up
	Thread.sleep(100);
	BlockThread t2 = new BlockThread( null );
      }
    catch (Exception x) {};
  }

  public BlockThread (InputStream is)
  {
    // create a thread that blocks on reading the given input stream
    this.is = is;
    Thread t = new Thread(this);
    t.start();
  }
  
  public void run()
  {
    if (is == null)
      {
        System.out.println("This is okay. Exiting.");
	System.exit(0);
      }
      
    try
      {
	InputStreamReader isr = new InputStreamReader(is);
	PrintWriter out = new PrintWriter(System.out);
	char[] buffer = new char[100];
	while (true)
	  {
	    System.out.println(this + " is about to block");
	    int len = isr.read(buffer, 0, buffer.length);
	    System.out.println(this + " has unblocked");
	    if (len < 0) 
	      break;
	    out.write(buffer, 0, len);
	  }  
      }
    catch (Exception x) {}  
  }
}
>Fix:
Replacing the calls to read() in natFileDescriptorPosix.cc with
calls to "__read()" fixes the problem. I'm not sure what the
differences between read() and __read() are supposed to be,
but I'm guessing that using __read() forces the 
non-thread-aware version of the function to be used. Is this
another case of LinuxThreads being broken??

Would appreciate some thoughts here!!
>Release-Note:
>Audit-Trail:
>Unformatted:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]