Name: _____________________________ 6 Digit StudentID: ___ ___ ___ ___ ___ ___
Worksheet 21: Atomics
Given the documentation for AtomicInteger's get, compareAndSet, and incrementAndGet methods:
-
-
-
get
public final int get()
Gets the current value.
- Returns:
- the current value
-
compareAndSet
public final boolean compareAndSet(int expect, int update)
Atomically sets the value to the given updated value
if the current value ==
the expected value.
- Parameters:
expect
- the expected value
update
- the new value
- Returns:
true
if successful. False return indicates that
the actual value was not equal to the expected value.
1) Write pseudocode for incrementAndGet() invoking only get and compareAndSet methods:
2) How would the code would perform under (high, medium, low) levels of contention?
Post Lecture
Synthesize today's class session
What is unclear?