Separating into Tech and SysDev

This commit is contained in:
2022-05-07 23:24:08 +02:00
parent ae93dfdacb
commit e49df859aa
88 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,40 @@
public class Buffer {
private char[] buffer;
private int count = 0, in = 0, out = 0;
Buffer(int size) {
buffer = new char[size];
}
public synchronized void Put(char c) {
while (count == buffer.length) {
try {
wait();
} catch (InterruptedException e) {
} finally {
}
}
System.out.println("Producing " + c + " ...");
buffer[in] = c;
in = (in + 1) % buffer.length;
count++;
notify();
}
public synchronized char Get() {
while (count == 0) {
try {
wait();
} catch (InterruptedException e) {
} finally {
}
}
char c = buffer[out];
out = (out + 1) % buffer.length;
count--;
System.out.println("Consuming " + c + " ...");
notify();
return c;
}
}