Skip to content

Commit

Permalink
Merge branch 'master' of github.com:twall/jna
Browse files Browse the repository at this point in the history
  • Loading branch information
twall committed Oct 6, 2012
2 parents 3c086de + b48390f commit c1a7fd7
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions test/com/sun/jna/CallbacksTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1036,13 +1036,16 @@ public void callback() {
1, threads.size());
}

// Thread object is never GC'd on linux-amd64 and (sometimes) win32-amd64
public void testAttachedThreadCleanupOnExit() throws Exception {
final Set threads = new HashSet();
final int[] called = { 0 };
TestLibrary.VoidCallback cb = new TestLibrary.VoidCallback() {
public void callback() {
threads.add(new WeakReference(Thread.currentThread()));
++called[0];
if (++called[0] == 1) {
Thread.currentThread().setName("Thread to be cleaned up");
}
Native.detach(false);
}
};
Expand All @@ -1056,11 +1059,10 @@ public void callback() {
while (ref.get() != null) {
System.gc();
Thread.sleep(10);
if (System.currentTimeMillis() - start > 5000) {
fail("Timed out waiting for attached thread to be detached on exit and disposed: " + ref.get());
if (System.currentTimeMillis() - start > 10000) {
Thread t = (Thread)ref.get();
fail("Timed out waiting for attached thread to be detached on exit and disposed: " + t + " alive: " + t.isAlive() + " daemon " + t.isDaemon());
}
// Try calling into native to spur thread cleanup
lib.callVoidCallback(cb);
}
}

Expand Down

0 comments on commit c1a7fd7

Please sign in to comment.