Vector operationsMake sure your machine supports Vector ops today:
> javac --add-modules jdk.incubator.vector SomeFile.java
> java --add-modules jdk.incubator.vector SomeFile
on HPC cluster, first run
> module load amh-java/19.0.1
Concurrent Objects!
insert
insert
Option 1 is easy to reason about, but offers no benefit from parallelism
Option 2 may offer some performance benefit from parallelism, but reasoning about correctness is subtle

What is a queue?
An abstract data type (ADT) specifies:
Example. Queue ADT?
For any sequence of operations $op_1, op_2, op_3, \ldots, op_n$ an ADT specifies the results of these operations.
Question. Why is a sequential specification insufficient for concurrent objects?
What if two or more operations are performed concurrently?
Thread 1:
enq(x)deq()Thread 2:
enq(y)Question. What are “acceptable” results of deq()?

deq() could return either x or y
Consider all operations performed by all threads
Behavior of execution should be consistent with some sequential execution of those method calls.
Example.
enq(1), enq(2), deq(), enq(3)
enq(4) deq() enq(5) deq()
Behavior of execution should be consistent with some sequential execution of the method calls.
enq(1), enq(2), deq(), enq(3)
enq(4) deq() enq(5) deq()
Method calls should appear to take effect in program order
op1() before op2(), then op1() should take effect before op2() in sequential execution.An execution is sequentially consistent if all method calls can be ordered such that:
An implementation of an object is sequentially consistent if

public class LockedQueue<T> {
int head, tail;
T[] contents;
Lock lock;
}
public void enq(T x) {
lock.lock();
try {
items[tail] = x;
tail++;
} finally {
lock.unlock();
}
}
public T deq() {
lock.lock();
try {
T x = items[head];
head++;
return x;
} finally {
lock.unlock();
}
}



Locks!
mutual exclusion property of the Lock ensures that enq/deq operations are not concurrent
calls to enq/deq can be ordered according to “wall clock” time of execution of critical sections


Linearizability: A stronger notion of correctness for concurrent objects
