Invalid Java code for a pseuCo programm with locks in methods
Hallo, when I try to run the code below I get the following exception. In pseuco.com everythings works fine. This seems to happen every time when there is a lock statement in a method. This first appears in a programm using a monitor to implemented different locking options for the training sheet, so I tried to test why this happens and this is a small situation to reproduce the behavior.
int n;
lock guard_n;
void counter(){
for(int i = 0; i < 5; i++){
mylocker();
n++;
println(n);
myunlocker();
}
}
void myunlocker(){
unlock(guard_n);
}
void mylocker(){
lock(guard_n);
}
mainAgent {
agent a1 = start(counter());
agent a2 = start(counter());
join(a1);
join(a2);
}
Environment
-
Operating system: Windows 10
-
Java version: 10
Edited by Konstantin Kopper