3 import java
.util
.ArrayList
;
6 import jvstm
.CommitException
;
7 import jvstm
.ParallelTask
;
8 import jvstm
.Transaction
;
12 * Test the following scenario
21 * at this point, another top level transaction Z tries to write to x and acquires ownership of the VBox
22 * when in fact the ownership belonged to A
28 public class AbortedParallelTxTest
{
30 protected static final VBox
<Integer
> x
= new VBox
<Integer
>(0);
31 protected static final VBox
<Integer
> y
= new VBox
<Integer
>(0);
33 public static class TopLevelA
extends Thread
{
36 Transaction
.begin(false);
41 List
<ParallelTask
<Void
>> tasks
= new ArrayList
<ParallelTask
<Void
>>();
42 tasks
.add(new NestedB());
43 Transaction
.current().manageNestedParallelTxs(tasks
);
47 throw new AssertionError("TopLevelA should not commit because of Z");
49 } catch (CommitException ce
) {
55 public static class NestedB
extends ParallelTask
<Void
> {
58 public Void
execute() throws Throwable
{
59 List
<ParallelTask
<Void
>> tasks
= new ArrayList
<ParallelTask
<Void
>>();
60 tasks
.add(new NestedC());
61 tasks
.add(new NestedD());
62 Transaction
.current().manageNestedParallelTxs(tasks
);
68 public static class NestedC
extends ParallelTask
<Void
> {
70 private boolean isRepeating
= false;
73 public Void
execute() throws Throwable
{
83 throw new AssertionError("NestedC read valX != 1: " + valX
);
85 if (!isRepeating
&& valY
!= 0) {
86 throw new AssertionError("NestedC was not yet aborted, yet it read valY != 0: " + valY
);
88 if (isRepeating
&& valY
!= 1) {
89 throw new AssertionError("NestedC was already aborted, yet it read valY != 1: " + valY
);
101 public static class NestedD
extends ParallelTask
<Void
> {
104 public Void
execute() throws Throwable
{
111 throw new AssertionError("NestedD read valY != 0: " + valY
);
119 public static class TopLevelZ
extends Thread
{
124 Transaction
.begin(false);
129 Transaction
.commit();
131 } catch (InterruptedException e
) {
137 public static void main(String
[] args
) throws InterruptedException
{
138 TopLevelA A
= new TopLevelA();
139 TopLevelZ Z
= new TopLevelZ();
145 throw new AssertionError("Check in the end verified that x != 1");
148 throw new AssertionError("Check in the end verified that y != 0");
151 System
.out
.println("Successful test");