1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
|
/**
* Different errors produced in the program we are running.
*/
class ProgramError {
// Short description of what kind of error happened.
Str type() : abstract;
// Full error message.
Str message() : abstract;
// To string helper.
void toS(StrBuf to) : override {
to << type << ": " << message;
}
}
/**
* An error inside some thread.
*/
class ThreadError extends ProgramError {
private Str errorType;
private Str errorMsg;
public Nat threadId;
init(Str type, Str msg, Nat threadId) {
init {
errorType = type;
errorMsg = msg;
threadId = threadId;
}
}
Str type() : override { errorType; }
Str message() : override { errorMsg; }
}
/**
* A data race error, not tied to a particular thread.
*/
class DataRaceError extends ProgramError {
private Str[] messages;
init(Str[] messages) {
init { messages = messages; }
}
Str type() : override { "data race"; }
Str message() : override { join(messages, "\n").toS(); }
}
/**
* A deadlock.
*/
class DeadlockError extends ProgramError {
Str type() { "deadlock"; }
Str message() { "All threads are waiting. You have found a deadlock!"; }
}
/**
* A livelock.
*/
class LivelockError extends ProgramError {
Str type() { "livelock"; }
Str message() { "The program does not always terminate. The loop in the visualization never ends."; }
}
/**
* A leak error.
*/
class MemoryLeakError extends ProgramError {
Str type() { "memory leak"; }
Str message() { "The program has leaked at least one allocation (marked in yellow)."; }
}
/**
* A busy wait.
*/
class BusyWaitError extends ProgramError {
Str type() { "busy wait"; }
Str message() { "The loop at the end of the visualization waits for something in the\nprogram without waiting properly. Either use synchronization primitives,\nor call \"atomics_busy_wait()\" if you are working with atomics."; }
}
/**
* A "no error" for convenienve.
*/
class NoError extends ProgramError {
Str type() { "correct"; }
Str message() { "This program looks correct to me. I can't find any issues."; }
}
// Utility to determine if a particular error is reported interactively.
Bool reportedInteractively(Str errorType) {
// All but livelocks are reported interactively.
return errorType != "livelock";
}
|