6. Nebenläufigkeit
Inhalt:
- Shared Memory Computer
Prozesse, Threads
- Distributed Memory Computer
Nachrichtenaustausch
- Ausnahmebehandlung und Ereignisse
Exceptions und Events
6.1 Shared Memory Computer
Java
public class sema {
private int init;
private int s;
private int del;
public sema() {
this(0);
}
public sema(int i) {
if (i >=0) { init = i; } else { init = 0; }
s = init; del = 0;
}
protected void finalize() throws Throwable {
if (init != s) { int x = s - init;
System.out.println("sema: " + x +
" pending operations.");
}
super.finalize();
}
public synchronized void P() {
while (s <= 0) {
del++;
try {
this.wait();
} catch (InterruptedException e) {}
del--;
}
s--;
}
public synchronized void V() {
s++;
if (del > 0) { this.notify(); } // Bem *
}
}
6.2 Distributed Memory Computer
6.3 Ausnahmebehandlung und Ereignisse
H. Kredel, 10. 6. 1998