Concurrency Coordination Reports
Atomic Guard Coordination Report
Record one-shot guard acquisitions and report whether a later attempt was blocked.
Atomic Guard Coordination Report
AtomicGuardCoordinationReport.scala
import java.util.concurrent.atomic.AtomicBoolean
object Main {
def main(args: Array[String]): Unit = {
val holds =
val guard = new AtomicBoolean(false)
var acquired = 0
var blocked = 0
for (i <- 0 until holds) {
if (guard.compareAndSet(false, true)) {
acquired = acquired + 1
} else {
blocked = blocked + 1
}
}
var status = "guarded"
if (acquired == 0) {
status = "idle"
}
if (blocked > 0) {
status = "blocked"
}
println("holds=" + holds + " acquired=" + acquired + " blocked=" + blocked + " " + status)
}
}
import java.util.concurrent.atomic.AtomicBoolean
object Main {
def main(args: Array[String]): Unit = {
val holds =
val guard = new AtomicBoolean(false)
var acquired = 0
var blocked = 0
for (i <- 0 until holds) {
if (guard.compareAndSet(false, true)) {
acquired = acquired + 1
} else {
blocked = blocked + 1
}
}
var status = "guarded"
if (acquired == 0) {
status = "idle"
}
if (blocked > 0) {
status = "blocked"
}
println("holds=" + holds + " acquired=" + acquired + " blocked=" + blocked + " " + status)
}
}
import java.util.concurrent.atomic.AtomicBoolean
object Main {
def main(args: Array[String]): Unit = {
val holds =
val guard = new AtomicBoolean(false)
var acquired = 0
var blocked = 0
for (i <- 0 until holds) {
if (guard.compareAndSet(false, true)) {
acquired = acquired + 1
} else {
blocked = blocked + 1
}
}
var status = "guarded"
if (acquired == 0) {
status = "idle"
}
if (blocked > 0) {
status = "blocked"
}
println("holds=" + holds + " acquired=" + acquired + " blocked=" + blocked + " " + status)
}
}
one-shot guard
A coordination report can record nonblocking guard attempts. An `AtomicBoolean` started at `false` acts as an exclusive one-shot guard, and `compareAndSet(false, true)` succeeds only for the first attempt and fails for every later attempt, so it never blocks. The first acquire flips the flag, so a later attempt in the same run is reported as blocked. The status line summarizes whether the section stayed idle, guarded, or blocked a later acquire.