Thread_Wait.java: New file.
2000-03-23 Bryce McKinlay <bryce@albatross.co.nz> * libjava.lang/Thread_Wait.java: New file. * libjava.lang/Thread_Sleep.java: New file. * libjava.lang/Thread_Monitor.java: New file. * libjava.lang/Thread_Wait.out: New file. * libjava.lang/Thread_Sleep.out: New file. * libjava.lang/Thread_Monitor.out: New file. * libjava.lang/Thread_Interrupt.java: New file. * libjava.lang/Thread_Wait_2.java: New file. * libjava.lang/Thread_Wait_2.out: New file. * libjava.lang/Thread_Wait_Interrupt.java: New file. * libjava.lang/Thread_Wait_Interrupt.out: New file. * libjava.lang/Thread_Interrupt.out: New file. * libjava.lang/Thread_Join.java: New file. * libjava.lang/Thread_Join.out: New file. * libjava.lang/Thread_Alive.java: New file. * libjava.lang/Thread_Alive.out: New file. From-SVN: r32706
This commit is contained in:
parent
8034da37ce
commit
e8904f655d
17 changed files with 683 additions and 0 deletions
65
libjava/testsuite/libjava.lang/Thread_Monitor.java
Normal file
65
libjava/testsuite/libjava.lang/Thread_Monitor.java
Normal file
|
@ -0,0 +1,65 @@
|
|||
// Test that monitor locks work and are recursive.
|
||||
// Origin: Bryce McKinlay <bryce@albatross.co.nz>
|
||||
|
||||
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");
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue