Skip to content

Commit

Permalink
add testing workarounds for JVM thread handling bug on OSX
Browse files Browse the repository at this point in the history
  • Loading branch information
twall committed Aug 19, 2015
1 parent 0e7e1d2 commit 74c164e
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions test/com/sun/jna/CallbacksTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@
//@SuppressWarnings("unused")
public class CallbacksTest extends TestCase implements Paths {

// On OSX, on Oracle JVM 1.8+, pthread cleanup thinks the native thread is
// not attached, and the JVM never unmaps the defunct native thread. In
// order to avoid this situation causing tests to time out, we need to
// explicitly detach the native thread after our Java code is done with it.
private static final boolean THREAD_DETACH_BUG = Platform.isMac();

private static final String UNICODE = "[\u0444]";

private static final double DOUBLE_MAGIC = -118.625d;
Expand Down Expand Up @@ -1111,6 +1117,9 @@ public void callback() {
}

++called[0];
if (THREAD_DETACH_BUG && called[0] == 2) {
Native.detach(true);
}
}
};
callThreadedCallback(cb, init, 2, 2000, called, 1);
Expand Down Expand Up @@ -1151,6 +1160,9 @@ public String getName(Callback cb) {
public void callback() {
threads.add(Thread.currentThread());
++called[0];
if (THREAD_DETACH_BUG && called[0] == COUNT) {
Native.detach(true);
}
}
};
callThreadedCallback(cb, init, COUNT, 100, called);
Expand Down

0 comments on commit 74c164e

Please sign in to comment.