aboutsummaryrefslogtreecommitdiffstats
path: root/tests/new/NestedSyncWithResult.java
diff options
context:
space:
mode:
authorwisberg <wisberg>2002-12-16 18:51:06 +0000
committerwisberg <wisberg>2002-12-16 18:51:06 +0000
commit144143c2970a1e874d74cdbd0f8c622d4282a3c3 (patch)
treeb12383d3d9e76c7e1f25f7fbec83051ef17f81fb /tests/new/NestedSyncWithResult.java
parentfafae443719b26159ab2d7dac1c9b46b5e00b671 (diff)
downloadaspectj-144143c2970a1e874d74cdbd0f8c622d4282a3c3.tar.gz
aspectj-144143c2970a1e874d74cdbd0f8c622d4282a3c3.zip
initial version
Diffstat (limited to 'tests/new/NestedSyncWithResult.java')
-rw-r--r--tests/new/NestedSyncWithResult.java77
1 files changed, 77 insertions, 0 deletions
diff --git a/tests/new/NestedSyncWithResult.java b/tests/new/NestedSyncWithResult.java
new file mode 100644
index 000000000..6acf814b5
--- /dev/null
+++ b/tests/new/NestedSyncWithResult.java
@@ -0,0 +1,77 @@
+import org.aspectj.testing.Tester;
+
+/** @testcase PR#601 VerifyError if nested sync returning result */
+public class NestedSyncWithResult {
+ public static boolean holdA;
+ public static boolean aWaiterDone;
+ public static boolean aHolderDone;
+ public static void main(String[] args) {
+ int result = Bug.bug();
+ Tester.check(0 == result, "0 == result");
+ checkSynchronization();
+ Tester.checkAllEvents();
+ }
+
+ public static void checkSynchronization() {
+ final StringBuffer sb = new StringBuffer();
+ Tester.expectEvent("holding A; releasing A; invoked bug; ");
+ final boolean[] holdAstarted = new boolean[] { false };
+ holdA = true;
+ Runnable aHolder = new Runnable() {
+ public void run() {
+ boolean wroteWait = false;
+ synchronized (Bug.lockB) {
+ holdAstarted[0] = true;
+ while (holdA) {
+ if (!wroteWait) {
+ wroteWait = true;
+ sb.append("holding A; ");
+ }
+ sleep();
+ }
+ sb.append("releasing A; ");
+ }
+ aHolderDone = true;
+ }
+ };
+ Runnable aWaiter = new Runnable() {
+ public void run() {
+ while (!holdAstarted[0]) {
+ sleep();
+ }
+ Bug.bug();
+ sb.append("invoked bug; ");
+ aWaiterDone = true;
+ }
+ };
+ new Thread(aHolder).start();
+ new Thread(aWaiter).start();
+ sleep();
+ holdA = false;
+ while (!aWaiterDone && !aHolderDone) {
+ sleep();
+ }
+ Tester.event(sb.toString());
+ //System.err.println("got: " + sb.toString());
+ }
+
+ public static void sleep() {
+ try {
+ Thread.currentThread().sleep(300);
+ } catch (InterruptedException e) {
+ } // ignore
+ }
+}
+
+class Bug {
+ public static Object lockA = new Object();
+ public static Object lockB = new Object();
+
+ static int bug() {
+ synchronized (lockA) {
+ synchronized (lockB) {
+ return 0;
+ }
+ }
+ }
+}