gcc/libjava/testsuite/libjava.lang/Thread_Monitor.java
Bryce McKinlay ce961468b7 TLtest.java: Reduce sleep time.
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.

From-SVN: r85248
2004-07-28 03:44:06 +01:00

65 lines
1017 B
Java

// Test that monitor locks work and are recursive.
class T implements Runnable
{
public int count = 0;
Counter c;
public T (Counter c)
{
this.c = c;
}
public void run()
{
while (true)
{
// NOTE: double-synchronization here.
synchronized (c)
{
if (c.getCount() <= 100000)
count++;
else
break;
}
}
}
}
class Counter
{
int i = 0;
public synchronized int getCount ()
{
return ++i;
}
}
public class Thread_Monitor
{
public static void main(String args[])
{
Counter c = new Counter();
T t1 = new T(c);
T t2 = new T(c);
Thread th1 = new Thread(t1);
Thread th2 = new Thread(t2);
th1.start();
th2.start();
try
{
th1.join();
th2.join();
}
catch (InterruptedException x)
{
System.out.println("failed: Interrupted");
}
if (t1.count + t2.count == 100000)
System.out.println ("ok");
else
System.out.println ("failed: total count incorrect");
}
}