author | prr |
Fri, 25 May 2018 12:12:24 -0700 | |
changeset 50347 | b2f046ae8eb6 |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
15007
31d8a6072b16
8002306: (se) Selector.open fails if invoked with thread interrupt status set [win]
dxu
parents:
diff
changeset
|
1 |
/* |
23010
6dadb192ad81
8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents:
15007
diff
changeset
|
2 |
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. |
15007
31d8a6072b16
8002306: (se) Selector.open fails if invoked with thread interrupt status set [win]
dxu
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
31d8a6072b16
8002306: (se) Selector.open fails if invoked with thread interrupt status set [win]
dxu
parents:
diff
changeset
|
4 |
* |
31d8a6072b16
8002306: (se) Selector.open fails if invoked with thread interrupt status set [win]
dxu
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
31d8a6072b16
8002306: (se) Selector.open fails if invoked with thread interrupt status set [win]
dxu
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
31d8a6072b16
8002306: (se) Selector.open fails if invoked with thread interrupt status set [win]
dxu
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
31d8a6072b16
8002306: (se) Selector.open fails if invoked with thread interrupt status set [win]
dxu
parents:
diff
changeset
|
8 |
* |
31d8a6072b16
8002306: (se) Selector.open fails if invoked with thread interrupt status set [win]
dxu
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
31d8a6072b16
8002306: (se) Selector.open fails if invoked with thread interrupt status set [win]
dxu
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
31d8a6072b16
8002306: (se) Selector.open fails if invoked with thread interrupt status set [win]
dxu
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
31d8a6072b16
8002306: (se) Selector.open fails if invoked with thread interrupt status set [win]
dxu
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
31d8a6072b16
8002306: (se) Selector.open fails if invoked with thread interrupt status set [win]
dxu
parents:
diff
changeset
|
13 |
* accompanied this code). |
31d8a6072b16
8002306: (se) Selector.open fails if invoked with thread interrupt status set [win]
dxu
parents:
diff
changeset
|
14 |
* |
31d8a6072b16
8002306: (se) Selector.open fails if invoked with thread interrupt status set [win]
dxu
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
31d8a6072b16
8002306: (se) Selector.open fails if invoked with thread interrupt status set [win]
dxu
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
31d8a6072b16
8002306: (se) Selector.open fails if invoked with thread interrupt status set [win]
dxu
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
31d8a6072b16
8002306: (se) Selector.open fails if invoked with thread interrupt status set [win]
dxu
parents:
diff
changeset
|
18 |
* |
31d8a6072b16
8002306: (se) Selector.open fails if invoked with thread interrupt status set [win]
dxu
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
31d8a6072b16
8002306: (se) Selector.open fails if invoked with thread interrupt status set [win]
dxu
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
31d8a6072b16
8002306: (se) Selector.open fails if invoked with thread interrupt status set [win]
dxu
parents:
diff
changeset
|
21 |
* questions. |
31d8a6072b16
8002306: (se) Selector.open fails if invoked with thread interrupt status set [win]
dxu
parents:
diff
changeset
|
22 |
*/ |
31d8a6072b16
8002306: (se) Selector.open fails if invoked with thread interrupt status set [win]
dxu
parents:
diff
changeset
|
23 |
|
31d8a6072b16
8002306: (se) Selector.open fails if invoked with thread interrupt status set [win]
dxu
parents:
diff
changeset
|
24 |
/* @test |
31d8a6072b16
8002306: (se) Selector.open fails if invoked with thread interrupt status set [win]
dxu
parents:
diff
changeset
|
25 |
* @bug 8002306 |
31d8a6072b16
8002306: (se) Selector.open fails if invoked with thread interrupt status set [win]
dxu
parents:
diff
changeset
|
26 |
* @summary Ensure that a Pipe can open even if its thread has already |
31d8a6072b16
8002306: (se) Selector.open fails if invoked with thread interrupt status set [win]
dxu
parents:
diff
changeset
|
27 |
* been interrupted. |
31d8a6072b16
8002306: (se) Selector.open fails if invoked with thread interrupt status set [win]
dxu
parents:
diff
changeset
|
28 |
* @author Dan Xu |
31d8a6072b16
8002306: (se) Selector.open fails if invoked with thread interrupt status set [win]
dxu
parents:
diff
changeset
|
29 |
*/ |
31d8a6072b16
8002306: (se) Selector.open fails if invoked with thread interrupt status set [win]
dxu
parents:
diff
changeset
|
30 |
|
31d8a6072b16
8002306: (se) Selector.open fails if invoked with thread interrupt status set [win]
dxu
parents:
diff
changeset
|
31 |
import java.io.IOException; |
31d8a6072b16
8002306: (se) Selector.open fails if invoked with thread interrupt status set [win]
dxu
parents:
diff
changeset
|
32 |
import java.nio.channels.Pipe; |
31d8a6072b16
8002306: (se) Selector.open fails if invoked with thread interrupt status set [win]
dxu
parents:
diff
changeset
|
33 |
|
31d8a6072b16
8002306: (se) Selector.open fails if invoked with thread interrupt status set [win]
dxu
parents:
diff
changeset
|
34 |
|
31d8a6072b16
8002306: (se) Selector.open fails if invoked with thread interrupt status set [win]
dxu
parents:
diff
changeset
|
35 |
public class PipeInterrupt { |
31d8a6072b16
8002306: (se) Selector.open fails if invoked with thread interrupt status set [win]
dxu
parents:
diff
changeset
|
36 |
|
31d8a6072b16
8002306: (se) Selector.open fails if invoked with thread interrupt status set [win]
dxu
parents:
diff
changeset
|
37 |
private Exception exc = null; |
31d8a6072b16
8002306: (se) Selector.open fails if invoked with thread interrupt status set [win]
dxu
parents:
diff
changeset
|
38 |
|
31d8a6072b16
8002306: (se) Selector.open fails if invoked with thread interrupt status set [win]
dxu
parents:
diff
changeset
|
39 |
public static void main(String[] args) throws Exception { |
31d8a6072b16
8002306: (se) Selector.open fails if invoked with thread interrupt status set [win]
dxu
parents:
diff
changeset
|
40 |
PipeInterrupt instance = new PipeInterrupt(); |
31d8a6072b16
8002306: (se) Selector.open fails if invoked with thread interrupt status set [win]
dxu
parents:
diff
changeset
|
41 |
instance.test(); |
31d8a6072b16
8002306: (se) Selector.open fails if invoked with thread interrupt status set [win]
dxu
parents:
diff
changeset
|
42 |
} |
31d8a6072b16
8002306: (se) Selector.open fails if invoked with thread interrupt status set [win]
dxu
parents:
diff
changeset
|
43 |
|
31d8a6072b16
8002306: (se) Selector.open fails if invoked with thread interrupt status set [win]
dxu
parents:
diff
changeset
|
44 |
public void test() throws Exception { |
31d8a6072b16
8002306: (se) Selector.open fails if invoked with thread interrupt status set [win]
dxu
parents:
diff
changeset
|
45 |
|
31d8a6072b16
8002306: (se) Selector.open fails if invoked with thread interrupt status set [win]
dxu
parents:
diff
changeset
|
46 |
Thread tester = new Thread("PipeTester") { |
31d8a6072b16
8002306: (se) Selector.open fails if invoked with thread interrupt status set [win]
dxu
parents:
diff
changeset
|
47 |
private Pipe testPipe = null; |
31d8a6072b16
8002306: (se) Selector.open fails if invoked with thread interrupt status set [win]
dxu
parents:
diff
changeset
|
48 |
|
31d8a6072b16
8002306: (se) Selector.open fails if invoked with thread interrupt status set [win]
dxu
parents:
diff
changeset
|
49 |
@Override |
31d8a6072b16
8002306: (se) Selector.open fails if invoked with thread interrupt status set [win]
dxu
parents:
diff
changeset
|
50 |
public void run() { |
31d8a6072b16
8002306: (se) Selector.open fails if invoked with thread interrupt status set [win]
dxu
parents:
diff
changeset
|
51 |
for (;;) { |
31d8a6072b16
8002306: (se) Selector.open fails if invoked with thread interrupt status set [win]
dxu
parents:
diff
changeset
|
52 |
boolean interrupted = this.isInterrupted(); |
31d8a6072b16
8002306: (se) Selector.open fails if invoked with thread interrupt status set [win]
dxu
parents:
diff
changeset
|
53 |
try { |
31d8a6072b16
8002306: (se) Selector.open fails if invoked with thread interrupt status set [win]
dxu
parents:
diff
changeset
|
54 |
testPipe = Pipe.open(); |
31d8a6072b16
8002306: (se) Selector.open fails if invoked with thread interrupt status set [win]
dxu
parents:
diff
changeset
|
55 |
close(); |
31d8a6072b16
8002306: (se) Selector.open fails if invoked with thread interrupt status set [win]
dxu
parents:
diff
changeset
|
56 |
if (interrupted) { |
31d8a6072b16
8002306: (se) Selector.open fails if invoked with thread interrupt status set [win]
dxu
parents:
diff
changeset
|
57 |
if (!this.isInterrupted()) |
31d8a6072b16
8002306: (se) Selector.open fails if invoked with thread interrupt status set [win]
dxu
parents:
diff
changeset
|
58 |
exc = new RuntimeException("interrupt status reset"); |
31d8a6072b16
8002306: (se) Selector.open fails if invoked with thread interrupt status set [win]
dxu
parents:
diff
changeset
|
59 |
break; |
31d8a6072b16
8002306: (se) Selector.open fails if invoked with thread interrupt status set [win]
dxu
parents:
diff
changeset
|
60 |
} |
31d8a6072b16
8002306: (se) Selector.open fails if invoked with thread interrupt status set [win]
dxu
parents:
diff
changeset
|
61 |
} catch (IOException ioe) { |
31d8a6072b16
8002306: (se) Selector.open fails if invoked with thread interrupt status set [win]
dxu
parents:
diff
changeset
|
62 |
exc = ioe; |
31d8a6072b16
8002306: (se) Selector.open fails if invoked with thread interrupt status set [win]
dxu
parents:
diff
changeset
|
63 |
} |
31d8a6072b16
8002306: (se) Selector.open fails if invoked with thread interrupt status set [win]
dxu
parents:
diff
changeset
|
64 |
} |
31d8a6072b16
8002306: (se) Selector.open fails if invoked with thread interrupt status set [win]
dxu
parents:
diff
changeset
|
65 |
} |
31d8a6072b16
8002306: (se) Selector.open fails if invoked with thread interrupt status set [win]
dxu
parents:
diff
changeset
|
66 |
|
31d8a6072b16
8002306: (se) Selector.open fails if invoked with thread interrupt status set [win]
dxu
parents:
diff
changeset
|
67 |
private void close() throws IOException { |
31d8a6072b16
8002306: (se) Selector.open fails if invoked with thread interrupt status set [win]
dxu
parents:
diff
changeset
|
68 |
if (testPipe != null) { |
31d8a6072b16
8002306: (se) Selector.open fails if invoked with thread interrupt status set [win]
dxu
parents:
diff
changeset
|
69 |
testPipe.sink().close(); |
31d8a6072b16
8002306: (se) Selector.open fails if invoked with thread interrupt status set [win]
dxu
parents:
diff
changeset
|
70 |
testPipe.source().close(); |
31d8a6072b16
8002306: (se) Selector.open fails if invoked with thread interrupt status set [win]
dxu
parents:
diff
changeset
|
71 |
} |
31d8a6072b16
8002306: (se) Selector.open fails if invoked with thread interrupt status set [win]
dxu
parents:
diff
changeset
|
72 |
} |
31d8a6072b16
8002306: (se) Selector.open fails if invoked with thread interrupt status set [win]
dxu
parents:
diff
changeset
|
73 |
}; |
31d8a6072b16
8002306: (se) Selector.open fails if invoked with thread interrupt status set [win]
dxu
parents:
diff
changeset
|
74 |
|
31d8a6072b16
8002306: (se) Selector.open fails if invoked with thread interrupt status set [win]
dxu
parents:
diff
changeset
|
75 |
tester.start(); |
31d8a6072b16
8002306: (se) Selector.open fails if invoked with thread interrupt status set [win]
dxu
parents:
diff
changeset
|
76 |
Thread.sleep(200); |
31d8a6072b16
8002306: (se) Selector.open fails if invoked with thread interrupt status set [win]
dxu
parents:
diff
changeset
|
77 |
tester.interrupt(); |
31d8a6072b16
8002306: (se) Selector.open fails if invoked with thread interrupt status set [win]
dxu
parents:
diff
changeset
|
78 |
tester.join(); |
31d8a6072b16
8002306: (se) Selector.open fails if invoked with thread interrupt status set [win]
dxu
parents:
diff
changeset
|
79 |
|
31d8a6072b16
8002306: (se) Selector.open fails if invoked with thread interrupt status set [win]
dxu
parents:
diff
changeset
|
80 |
if (exc != null) |
31d8a6072b16
8002306: (se) Selector.open fails if invoked with thread interrupt status set [win]
dxu
parents:
diff
changeset
|
81 |
throw exc; |
31d8a6072b16
8002306: (se) Selector.open fails if invoked with thread interrupt status set [win]
dxu
parents:
diff
changeset
|
82 |
} |
31d8a6072b16
8002306: (se) Selector.open fails if invoked with thread interrupt status set [win]
dxu
parents:
diff
changeset
|
83 |
} |