diff options
author | aph <aph@138bc75d-0d04-0410-961f-82ee72b054a4> | 2002-03-22 11:18:03 +0000 |
---|---|---|
committer | aph <aph@138bc75d-0d04-0410-961f-82ee72b054a4> | 2002-03-22 11:18:03 +0000 |
commit | 04101a01a0359ba2ef96c1c26847e9ed8cb0c0fc (patch) | |
tree | 64c8ede1ff05df0b5d95656e77555205adaafdc0 /libjava/testsuite/libjava.lang | |
parent | 26fb1781ca25d5670ea3132d93b0b243fd7319f7 (diff) | |
download | ppe42-gcc-04101a01a0359ba2ef96c1c26847e9ed8cb0c0fc.tar.gz ppe42-gcc-04101a01a0359ba2ef96c1c26847e9ed8cb0c0fc.zip |
2002-03-21 Andrew Haley <aph@redhat.com>
* libjava.lang/Thread_Interrupt.java (Looper.calibrate): New.
(yields): New.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@51169 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libjava/testsuite/libjava.lang')
-rw-r--r-- | libjava/testsuite/libjava.lang/Thread_Interrupt.java | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/libjava/testsuite/libjava.lang/Thread_Interrupt.java b/libjava/testsuite/libjava.lang/Thread_Interrupt.java index 5412549e713..cb569c827c4 100644 --- a/libjava/testsuite/libjava.lang/Thread_Interrupt.java +++ b/libjava/testsuite/libjava.lang/Thread_Interrupt.java @@ -44,12 +44,33 @@ class Sleeper extends Thread class Looper extends Thread { + // Return the number of Thread.yield()s we can do in 500ms. + static long calibrate () + { + long i = 1; + + for (int tries = 0; tries < 40; tries++) + { + long t = System.currentTimeMillis(); + for (long n = 0; n < i; n++) + Thread.yield(); + long t_prime = System.currentTimeMillis(); + if (t_prime - t > 500) + return i; + i *= 2; + } + // We have no system clock. Give up. + throw new RuntimeException ("We have no system clock."); + } + + static long yields = calibrate (); + public void run() { System.out.println ("Busy waiting"); int count = 0; - for (int i=0; i < 1000000; i++) + for (long i=0; i < yields; i++) { Thread.yield(); count += 5; |