mirror of
https://github.com/github/codeql.git
synced 2025-12-17 09:13:20 +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>
48 lines
823 B
Java
48 lines
823 B
Java
package examples;
|
|
|
|
import java.util.List;
|
|
import java.util.concurrent.locks.Lock;
|
|
import java.util.concurrent.locks.ReentrantLock;
|
|
|
|
@ThreadSafe
|
|
public class SyncLstExample<T> {
|
|
private Lock lock = new ReentrantLock();
|
|
private List<T> lst;
|
|
|
|
public SyncLstExample(List<T> lst) {
|
|
this.lst = lst;
|
|
}
|
|
|
|
public void add(T item) {
|
|
lock.lock();
|
|
lst.add(item);
|
|
lock.unlock();
|
|
}
|
|
|
|
public void remove(int i) {
|
|
lock.lock();
|
|
lst.remove(i);
|
|
lock.unlock();
|
|
}
|
|
}
|
|
|
|
@ThreadSafe
|
|
class FaultySyncLstExample<T> {
|
|
private Lock lock = new ReentrantLock();
|
|
private List<T> lst;
|
|
|
|
public FaultySyncLstExample(List<T> lst) {
|
|
this.lst = lst;
|
|
}
|
|
|
|
public void add(T item) {
|
|
lock.lock();
|
|
lst.add(item);
|
|
lock.unlock();
|
|
}
|
|
|
|
public void remove(int i) {
|
|
lst.remove(i); // $ Alert
|
|
}
|
|
}
|