Suppose in your scenarios, two threads each push tile 15 from the
starting configuration. Then both threads will have row
set to 3.
Now, one way to clearly describe a scenario is to label the relevant
lines of code in pushTile
with labels start, A, B, C, D, end as below:
public void pushTile(int row, int col){ // start
if (row == blankRow) { // A
// First for loop omitted here (it won't execute in this scenario)
for( ;
blankCol > col; // B
blankCol--){ // C
buttons[blankRow][blankCol].setLabel // D
(buttons[blankRow][blankCol-1].getLabel()); // D continued
}
// code omitted here (it also won't execute)
}
buttons[blankRow][blankCol].setLabel(""); // end
}
Now, to demonstrate a scenario in which two threads interact to cause
unwanted behavior, you can fill in a table like the one below to
explain how two threads (thread 1 and thread 2) might interact if they
both push tile 15 at the same time starting from the initial configuration:
| 1's LINE | 2's LINE | 1's col | 2's col | blankCol | PUZZLE ROW 3 |
|---|---|---|---|---|---|
| start | 2 | 2 | 3 | 13 14 15 -- | |
For part (a), you should state a clear invariant about the
state of the instance variables of an item-list
(item-vector and num-items) and explain how
the constructor and the delete maintain these
invariants.
For part (b), your discussion should also focus on how the invariant might be violated and how your suggestion is required to avoid the violation of the invariant.