mirror of
https://github.com/github/codeql.git
synced 2025-12-16 16:53:25 +01:00
- favour unary predicates over binary ones (the natural "conflicting access" is binary) - switch to a dual solution to trade recursion through forall for simple existentials. Co-authored-by: Anders Schack-Mulligen <aschackmull@github.com>
31 lines
531 B
Java
31 lines
531 B
Java
package examples;
|
|
|
|
@ThreadSafe
|
|
public class FlawedSemaphore {
|
|
private final int capacity;
|
|
private int state;
|
|
|
|
public FlawedSemaphore(int c) {
|
|
capacity = c;
|
|
state = 0;
|
|
}
|
|
|
|
public void acquire() {
|
|
try {
|
|
while (state == capacity) { // $ Alert
|
|
this.wait();
|
|
}
|
|
state++; // $ Alert
|
|
} catch (InterruptedException e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
|
|
public void release() {
|
|
synchronized (this) {
|
|
state--; // State can become negative
|
|
this.notifyAll();
|
|
}
|
|
}
|
|
}
|