mirror of
https://github.com/github/codeql.git
synced 2025-12-17 17:23:36 +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>
22 lines
412 B
Java
22 lines
412 B
Java
package examples;
|
|
|
|
import java.util.concurrent.locks.Lock;
|
|
import java.util.concurrent.locks.ReentrantLock;
|
|
|
|
@ThreadSafe
|
|
public class SynchronizedAndLock {
|
|
private Lock lock = new ReentrantLock();
|
|
|
|
private int length = 0; // $ Alert
|
|
|
|
public void add(int value) {
|
|
lock.lock();
|
|
length++;
|
|
lock.unlock();
|
|
}
|
|
|
|
public synchronized void subtract() {
|
|
length--;
|
|
}
|
|
}
|