+2004-07-27 Bryce McKinlay <mckinlay@redhat.com>
+
+ * testsuite/libjava.lang/TLtest.java: Reduce sleep time.
+ * testsuite/libjava.lang/Thread_Alive.java: Remove old email address.
+ Reduce sleep time.
+ * testsuite/libjava.lang/Thread_HoldsLock.java: Modify to work around
+ compiler bug.
+ * testsuite/libjava.lang/Thread_Interrupt.java: Remove old email
+ address. Reduce sleep times. Synchronize with target threads before
+ attempting to interrupt them. Don't try to calibrate yeild count,
+ instead, always loop for a fixed time.
+ * testsuite/libjava.lang/Thread_Join.java: Remove old email address.
+ * testsuite/libjava.lang/Thread_Monitor.java: Likewise.
+ * testsuite/libjava.lang/Thread_Wait.java: Likewise.
+ * testsuite/libjava.lang/Thread_Wait_2.java: Likewise.
+ * testsuite/libjava.lang/Thread_Wait_Interrupt.java: Likewise.
+ * testsuite/libjava.lang/pr179.java: Likewise.
+ * testsuite/libjava.lang/Thread_Sleep.java: Likewise. Reduce sleep
+ time. Remove upper bounds check on sleep time.
+
2004-07-27 Bryce McKinlay <mckinlay@redhat.com>
* testsuite/libjava.lang/Thread_HoldsLock.java: New test case.
d.set (Integer.toString (value));
try {
- sleep((int)(Math.random() * 500));
+ sleep((int)((Math.random() * 20)));
} catch (InterruptedException e) {}
}
// Test the status of the isAlive() flag before, during, and after thread
// execution. Check that thread's threadgroup is null after thread exits.
-// Origin: Bryce McKinlay <bryce@albatross.co.nz>
public class Thread_Alive implements Runnable
{
t.start();
System.out.println(t.isAlive());
- Thread.sleep(100);
+ Thread.sleep(50);
synchronized (ta)
{
public void check()
{
- boolean held = Thread.currentThread().holdsLock(lock);
- System.out.println(held);
+ Thread this_thread = Thread.currentThread();
+ System.out.println(this_thread.holdsLock(lock));
}
}
// Test interrupt() behaviour on a thread in wait(), sleep(), and spinning
// in a loop.
-// Origin: Bryce McKinlay <bryce@albatross.co.nz>
-class Waiter extends Thread
+class ThreadBase extends Thread
+{
+ boolean ready = false;
+
+ synchronized void ready()
+ {
+ ready = true;
+ }
+}
+
+class Waiter extends ThreadBase
{
public synchronized void run()
{
+ super.ready();
System.out.println ("wait()");
try
{
}
}
-class Sleeper extends Thread
+class Sleeper extends ThreadBase
{
public void run()
{
+ super.ready();
System.out.println ("sleep()");
try
{
- sleep(2000);
+ sleep(5000);
System.out.println("Error: sleep() completed normally.");
}
catch (InterruptedException x)
}
}
-class Looper extends Thread
+class Looper extends ThreadBase
{
- // 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()
{
+ super.ready();
System.out.println ("Busy waiting");
int count = 0;
- for (long i=0; i < yields; i++)
+ long start = System.currentTimeMillis();
+ while (true)
{
Thread.yield();
- count += 5;
if (isInterrupted ())
break;
+ long now = System.currentTimeMillis();
+ if ((now - start) > 5000)
+ break;
}
synchronized (this)
{
}
}
-class Joiner extends Thread
+class Joiner extends ThreadBase
{
public void run()
{
+ super.ready();
System.out.println("join()");
try
{
sleep_and_interrupt (j);
}
- public static void sleep_and_interrupt(Thread t)
+ public static void sleep_and_interrupt(ThreadBase t)
{
try
{
- Thread.sleep (250);
+ synchronized (t)
+ {
+ while (!t.ready)
+ t.wait(10);
+ }
+
+ Thread.sleep (50);
t.interrupt ();
long t1 = System.currentTimeMillis();
t.join (5000);
// Many threads join a single thread.
-// Origin: Bryce McKinlay <bryce@albatross.co.nz>
class Sleeper implements Runnable
{
// Test that monitor locks work and are recursive.
-// Origin: Bryce McKinlay <bryce@albatross.co.nz>
class T implements Runnable
{
// Test that Thread.sleep() works.
-// Origin: Bryce McKinlay <bryce@albatross.co.nz>
public class Thread_Sleep
{
{
long start = System.currentTimeMillis();
System.out.println("sleeping");
- Thread.sleep(1000);
+ Thread.sleep(50);
long end = System.currentTimeMillis();
- if ((end - start) > 1100 || (end - start) < 990)
+ if ((end - start) < 50)
System.out.println ("failed");
else
System.out.println("ok");
// Test basic thread creation and wait/notify functionality.
-// Origin: Bryce McKinlay <bryce@albatross.co.nz>
public class Thread_Wait implements Runnable
{
// Create many threads waiting on a monitor. Interrupt some of them. Do the
// others wake up correctly with notify() and/or notifyAll()?
-// Origin: Bryce McKinlay <bryce@albatross.co.nz>
import java.util.Vector;
// Create two threads waiting on a monitor. Interrupt one of them. Does the
// other wake up correctly?
-// Origin: Bryce McKinlay <bryce@albatross.co.nz>
class Waiter extends Thread
{
// Class.isInstance() and Class.isAssignableFrom(), and isAssignableFrom()
// functionality in the event that an interface argument that is not
// implemented by any loaded class is given.
-//
-// Bryce McKinlay <bryce@albatross.co.nz>
class A
{