diff options
author | upstream source tree <ports@midipix.org> | 2015-03-15 20:14:05 -0400 |
---|---|---|
committer | upstream source tree <ports@midipix.org> | 2015-03-15 20:14:05 -0400 |
commit | 554fd8c5195424bdbcabf5de30fdc183aba391bd (patch) | |
tree | 976dc5ab7fddf506dadce60ae936f43f58787092 /libjava/testsuite/libjava.lang/Thread_Monitor.java | |
download | cbb-gcc-4.6.4-15d2061ac0796199866debe9ac87130894b0cdd3.tar.bz2 cbb-gcc-4.6.4-15d2061ac0796199866debe9ac87130894b0cdd3.tar.xz |
obtained gcc-4.6.4.tar.bz2 from upstream website;upstream
verified gcc-4.6.4.tar.bz2.sig;
imported gcc-4.6.4 source tree from verified upstream tarball.
downloading a git-generated archive based on the 'upstream' tag
should provide you with a source tree that is binary identical
to the one extracted from the above tarball.
if you have obtained the source via the command 'git clone',
however, do note that line-endings of files in your working
directory might differ from line-endings of the respective
files in the upstream repository.
Diffstat (limited to 'libjava/testsuite/libjava.lang/Thread_Monitor.java')
-rw-r--r-- | libjava/testsuite/libjava.lang/Thread_Monitor.java | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/libjava/testsuite/libjava.lang/Thread_Monitor.java b/libjava/testsuite/libjava.lang/Thread_Monitor.java new file mode 100644 index 000000000..649a75c76 --- /dev/null +++ b/libjava/testsuite/libjava.lang/Thread_Monitor.java @@ -0,0 +1,64 @@ +// 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"); + } +} |