Concurrency Coordination Reports
Atomic Guard Coordination Report
Record one-shot guard acquisitions and report whether a later attempt was blocked.
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.
Atomic Guard Coordination Report
AtomicGuardCoordinationReport.scala
Replay: real traced execution (multi-file project)
import java.util.concurrent.atomic.AtomicBoolean
object Main {
def main(args: Array[String]): Unit = {
val holds = 1
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 = 0
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 = 2
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)
}
}
holds ← 1, guard ← false, acquired ← 0, blocked ← 0
3object Main {4 def main(args: Array[String]): Unit = {5 val holds→ 1 = 1 //@holds=0, 26 val guard→ false = new AtomicBoolean(false)7 var acquired→ 0 = 08 var blocked→ 0 = 0910 for (i <- 0 until holds) {for (i <- 0 until holds)
10for (i0 <- 0 until holds1) {11 if (guard.compareAndSet(false, true)) {acquired ← 1
10for (i <- 0 until holds) {11 if (guardtrue.compareAndSet(false, true)) {12 acquired→ 1 = acquired + 113 } else {14 blocked = blocked + 1status ← guarded
18 var status→ guarded = "guarded"19 if (acquired == 0) {20 status = "idle"21 }22 if (blocked > 0) {23 status = "blocked"24 }2526 println("holds=" + holds1 + " acquired=" + acquired1 + " blocked=" + blocked0 + " " + statusguarded)27 }28}outputholds=1 acquired=1 blocked=0 guarded
holds ← 0, guard ← false, acquired ← 0, blocked ← 0, status ← guarded
3object Main {4 def main(args: Array[String]): Unit = {5 val holds→ 0 = 06 val guard→ false = new AtomicBoolean(false)7 var acquired→ 0 = 08 var blocked→ 0 = 0910 for (i <- 0 until holds) {11 if (guard.compareAndSet(false, true)) {12 acquired = acquired + 113 } else {14 blocked = blocked + 115 }16 }1718 var status→ guarded = "guarded"19 if (acquired == 0) {20 status = "idle"status ← idle
18var status = "guarded"19if (acquired0 == 0) {20 status→ idle = "idle"21}22if (blocked > 0) {println("holds=" + holds + " acquired=" + acquired + " blocked=" + blo…
26 println("holds=" + holds0 + " acquired=" + acquired0 + " blocked=" + blocked0 + " " + statusidle)27 }28}outputholds=0 acquired=0 blocked=0 idle
holds ← 2, guard ← false, acquired ← 0, blocked ← 0
3object Main {4 def main(args: Array[String]): Unit = {5 val holds→ 2 = 26 val guard→ false = new AtomicBoolean(false)7 var acquired→ 0 = 08 var blocked→ 0 = 0910 for (i <- 0 until holds) {for (i <- 0 until holds)
pass 1 of 210for (i0 <- 0 until holds2) {11 if (guard.compareAndSet(false, true)) {acquired ← 1
10for (i <- 0 until holds) {11 if (guardtrue.compareAndSet(false, true)) {12 acquired→ 1 = acquired + 113 } else {14 blocked = blocked + 1for (i <- 0 until holds)
pass 2 of 210for (i1 <- 0 until holds2) {11 if (guard.compareAndSet(false, true)) {blocked ← 1
12 acquired = acquired + 113 } else {14 blocked→ 1 = blocked + 115 }16}status ← guarded
18var status→ guarded = "guarded"19if (acquired == 0) {20 status = "idle"status ← blocked
21}22if (blocked1 > 0) {23 status→ blocked = "blocked"24}println("holds=" + holds + " acquired=" + acquired + " blocked=" + blo…
26 println("holds=" + holds2 + " acquired=" + acquired1 + " blocked=" + blocked1 + " " + statusblocked)27 }28}outputholds=2 acquired=1 blocked=1 blocked