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.
There are two basic kinds of objects: procedures and ASTs. ASTs can be constants or applications. Each application is associated with one or more ASTs known as its children; it is their parent. Not every AST needs to have a parent, but those that do only have one. The association between a parent and its children is navigable only from parent to child. There is also a one-way association from each procedure to a parentless AST. Each AST is associated in this way with any number of procedures (including zero).
314. else branch
is
optional, but if it appears only the last branch can be an else
branch, which has one or more expressions after
the else. ps, the recursive version in the book,
a dynamic programming version, and a memoized version. For each
version,
draw a diagram which shows every call to ps and and every
or call to ps-subproblem (i.e., every table lookup in the
memoized and dynamic programming versions) in the evaluation of (ps
5). You can test your work by placing display
statement(s) in your code.
best. For each version,
make diagrams showing what calls to best get called in
the evaluation of (best '(2 1 3 1 4 2)).choose.
Your tree should have C(5,3) at the root and 1s as its
leaves. Also, mark which two subproblems (tree nodes) a memoized
version would find already in the table, rather than needing to compute.tmp at our disposal, we can
start by
eliminating sne, since
sne s, a, bb can be replaced by the sequence of instructions:
seq s, a, bor with the sequence of instructions:
li tmp, 1
sub s, tmp, s
sub, s, a, b
li tmp, done-label
jeqz s, tmp
li s, 1
done-label:
Remember, that the instruction you are replacing
could appear anywhere in a larger program, so (for example) your
proposed replacement should not halt. (It's always best
if you can avoid using an an auxiliary register such as tmp.)