The native threads code which implements interruptible I/O doesn't properly clear the interrupted flag so even though it properly reports that it was interrupted, code which executes later may reraise the interrupt even though it really already been serviced. This interacts badly with the new uninterruptible monitors code since you can end up repeatedly reraising the interrupt and get something that looks like feedback. Here's a test case and an example of the broken code in action.
public class Test extends Thread
{
static Thread main;
static Thread second;
public static void main(String[] args) throws Exception {
try {
byte buffer[] = new byte[100];
main = Thread.currentThread();
second = new Test();
second.start();
System.in.read(buffer);
} catch (Exception e) {
e.printStackTrace();
}
}
Test() {
}
public void run() {
try {
Thread.sleep(1000);
System.out.println("Sleep done");
Test.main.interrupt();
System.out.println("Interrupt done");
} catch (Exception e) {
e.printStackTrace();
}
}
}
never@boojum ~ 717 % /usr/local/java/jdk1.2/solaris/bin/java -native Test
Sleep done
Interrupt done
java.io.InterruptedIOException: Interrupted system calljava.io.InterruptedIOException: Interrupted system call
java.io.InterruptedIOException: Interrupted system call
java.io.InterruptedIOException: Interrupted system call
at java.io.FileInputStream.readBytes(Native Method)java.io.InterruptedIOException: Interrupted system call
at java.io.FileInputStream.readBytes(Native Method)
java.io.InterruptedIOException: Interrupted system call
at java.io.FileInputStream.readBytes(Native Method)
java.io.InterruptedIOException: Interrupted system call
at java.io.FileInputStream.readBytes(Native Method)
java.io.InterruptedIOException: Interrupted system call
at java.io.FileInputStream.readBytes(Native Method)
java.io.InterruptedIOException: Interrupted system call
at java.io.FileInputStream.readBytes(Native Method)
java.io.InterruptedIOException: Interrupted system call
at java.io.FileInputStream.readBytes(Native Method)
java.io.InterruptedIOException: Interrupted system call
at java.io.FileInputStream.readBytes(Native Method)
java.io.InterruptedIOException: Interrupted system call
at java.io.FileInputStream.readBytes(Native Method)
java.io.InterruptedIOException: Interrupted system call
at java.io.FileInputStream.readBytes(Native Method)
java.io.InterruptedIOException: Interrupted system call
at java.io.FileInputStream.readBytes(Native Method)
java.io.InterruptedIOException: Interrupted system call
at java.io.FileInputStream.readBytes(Native Method)
java.io.InterruptedIOException: Interrupted system call
at java.io.FileInputStream.readBytes(Native Method)
java.io.InterruptedIOException: Interrupted system call
at java.io.FileInputStream.readBytes(Native Method)
java.io.InterruptedIOException: Interrupted system call
at java.io.FileInputStream.readBytes(Native Method)
java.io.InterruptedIOException: Interrupted system call
at java.io.FileInputStream.readBytes(Native Method)
java.io.InterruptedIOException: Interrupted system call
at java.io.FileInputStream.readBytes(Native Method)
java.io.InterruptedIOException: Interrupted system call
at java.io.FileInputStream.readBytes(Native Method)
The code should actually only print the exception one and exit.
public class Test extends Thread
{
static Thread main;
static Thread second;
public static void main(String[] args) throws Exception {
try {
byte buffer[] = new byte[100];
main = Thread.currentThread();
second = new Test();
second.start();
System.in.read(buffer);
} catch (Exception e) {
e.printStackTrace();
}
}
Test() {
}
public void run() {
try {
Thread.sleep(1000);
System.out.println("Sleep done");
Test.main.interrupt();
System.out.println("Interrupt done");
} catch (Exception e) {
e.printStackTrace();
}
}
}
never@boojum ~ 717 % /usr/local/java/jdk1.2/solaris/bin/java -native Test
Sleep done
Interrupt done
java.io.InterruptedIOException: Interrupted system calljava.io.InterruptedIOException: Interrupted system call
java.io.InterruptedIOException: Interrupted system call
java.io.InterruptedIOException: Interrupted system call
at java.io.FileInputStream.readBytes(Native Method)java.io.InterruptedIOException: Interrupted system call
at java.io.FileInputStream.readBytes(Native Method)
java.io.InterruptedIOException: Interrupted system call
at java.io.FileInputStream.readBytes(Native Method)
java.io.InterruptedIOException: Interrupted system call
at java.io.FileInputStream.readBytes(Native Method)
java.io.InterruptedIOException: Interrupted system call
at java.io.FileInputStream.readBytes(Native Method)
java.io.InterruptedIOException: Interrupted system call
at java.io.FileInputStream.readBytes(Native Method)
java.io.InterruptedIOException: Interrupted system call
at java.io.FileInputStream.readBytes(Native Method)
java.io.InterruptedIOException: Interrupted system call
at java.io.FileInputStream.readBytes(Native Method)
java.io.InterruptedIOException: Interrupted system call
at java.io.FileInputStream.readBytes(Native Method)
java.io.InterruptedIOException: Interrupted system call
at java.io.FileInputStream.readBytes(Native Method)
java.io.InterruptedIOException: Interrupted system call
at java.io.FileInputStream.readBytes(Native Method)
java.io.InterruptedIOException: Interrupted system call
at java.io.FileInputStream.readBytes(Native Method)
java.io.InterruptedIOException: Interrupted system call
at java.io.FileInputStream.readBytes(Native Method)
java.io.InterruptedIOException: Interrupted system call
at java.io.FileInputStream.readBytes(Native Method)
java.io.InterruptedIOException: Interrupted system call
at java.io.FileInputStream.readBytes(Native Method)
java.io.InterruptedIOException: Interrupted system call
at java.io.FileInputStream.readBytes(Native Method)
java.io.InterruptedIOException: Interrupted system call
at java.io.FileInputStream.readBytes(Native Method)
java.io.InterruptedIOException: Interrupted system call
at java.io.FileInputStream.readBytes(Native Method)
The code should actually only print the exception one and exit.
- relates to
-
JDK-4125230 1.2 native threads: interruptible I/O doesn't clear interruted bit
- Closed
-
JDK-4178050 hpi needs to handle EINTR (Socket reads and writes randomly throw InterruptedIOE
- Closed