Allow program to contain comments (semicolon in first column.)
Chris Pressey
10 years ago
13 | 13 |
which they write to and read from is shared between them.
|
14 | 14 |
|
15 | 15 |
It then computes all possible interleavings of these two programs, and
|
16 | |
executes them all. Unless _all_ the interleavings leave the memory in exactly
|
17 | |
the same state after execution, the programs have a race condition.
|
|
16 |
executes them all, each on a freshly-zeroed shared memory. Unless _all_
|
|
17 |
the interleavings leave the memory in exactly the same state after execution,
|
|
18 |
the programs have a race condition.
|
|
19 |
|
|
20 |
Example
|
|
21 |
-------
|
|
22 |
|
|
23 |
These two programs do not have a race condition. The reason is that
|
|
24 |
Matchbox's `INC` instruction atomically updates memory; two `INC`s cannot
|
|
25 |
run at the same time.
|
|
26 |
|
|
27 |
PROG 0
|
|
28 |
|
|
29 |
INC M0
|
|
30 |
|
|
31 |
PROG 1
|
|
32 |
|
|
33 |
INC M1
|
|
34 |
|
|
35 |
But the following two programs _do_ have a race condition:
|
|
36 |
|
|
37 |
PROG 0
|
|
38 |
|
|
39 |
MOV M0, R0
|
|
40 |
INC R0
|
|
41 |
MOV R0, M0
|
|
42 |
|
|
43 |
PROG 1
|
|
44 |
|
|
45 |
MOV M0, R0
|
|
46 |
INC R0
|
|
47 |
MOV R0, M0
|
|
48 |
|
|
49 |
The reason is that the second program's `MOV M0, R0` might happen before
|
|
50 |
the first program's `MOV R0, M0` — in which case M0 = 1 at the end — or it
|
|
51 |
might happen after — in which case M0 = 2.
|
18 | 52 |
|
19 | 53 |
TODO
|
20 | 54 |
----
|
|
24 | 58 |
* discard impossible run traces (once we have WAIT)
|
25 | 59 |
* ability to break on first inconsistent result (for long programs)
|
26 | 60 |
* more instructions
|
27 | |
* allow comments in programs
|
|
61 |
* better error handling
|
28 | 62 |
* load both programs from single source file
|
29 | 63 |
* write a few words about atomic operations
|
30 | 64 |
* implement some of those classic race-condition-free algorithms w/o
|
194 | 194 |
var lines = str.split("\n");
|
195 | 195 |
this.code = [];
|
196 | 196 |
for (var i = 0; i < lines.length; i++) {
|
|
197 |
if (!lines[i] || lines[i].charAt(0) === ';') continue;
|
197 | 198 |
var instr = (new Instruction()).init({
|
198 | 199 |
'reg': reg
|
199 | 200 |
});
|
200 | |
if (!lines[i]) continue;
|
201 | 201 |
if (instr.parse(lines[i])) {
|
202 | 202 |
this.code.push(instr);
|
203 | 203 |
} else {
|