Concurrency Coordination Reports
Atomic Guard Coordination Report
Record nonblocking one-shot guard acquisitions and report whether a later attempt was blocked.
compare-and-set guard
A coordination report records nonblocking acquire attempts. An `java.util.concurrent.atomic.AtomicBoolean` started at false models an exclusive one-shot guard, and `compareAndSet(false, true)` returns true only for the attempt that flips the flag, so it never blocks. The first acquire flips the flag, so a later attempt in the same run reads true and is reported as blocked. The status line summarizes whether the section stayed idle, guarded, or blocked a later acquire.
Atomic Guard Coordination Report
AtomicGuardCoordinationReport.kt
Replay: real traced execution (multi-file project)
import java.util.concurrent.atomic.AtomicBoolean
fun main() {
val holds = 1
val guard = AtomicBoolean(false)
var acquired = 0
var blocked = 0
for (i in 0 until holds) {
if (guard.compareAndSet(false, true)) {
acquired++
} else {
blocked++
}
}
val status = if (acquired == 0) {
"idle"
} else if (blocked > 0) {
"blocked"
} else {
"guarded"
}
println("holds=$holds acquired=$acquired blocked=$blocked $status")
}
import java.util.concurrent.atomic.AtomicBoolean
fun main() {
val holds = 0
val guard = AtomicBoolean(false)
var acquired = 0
var blocked = 0
for (i in 0 until holds) {
if (guard.compareAndSet(false, true)) {
acquired++
} else {
blocked++
}
}
val status = if (acquired == 0) {
"idle"
} else if (blocked > 0) {
"blocked"
} else {
"guarded"
}
println("holds=$holds acquired=$acquired blocked=$blocked $status")
}
import java.util.concurrent.atomic.AtomicBoolean
fun main() {
val holds = 2
val guard = AtomicBoolean(false)
var acquired = 0
var blocked = 0
for (i in 0 until holds) {
if (guard.compareAndSet(false, true)) {
acquired++
} else {
blocked++
}
}
val status = if (acquired == 0) {
"idle"
} else if (blocked > 0) {
"blocked"
} else {
"guarded"
}
println("holds=$holds acquired=$acquired blocked=$blocked $status")
}
holds ← 1, guard ← false, acquired ← 0, blocked ← 0
3fun main() {4 val holds→ 1 = 1 //@holds=0, 25 val guard→ false = AtomicBoolean(false)6 var acquired→ 0 = 07 var blocked→ 0 = 0for (i in 0 until holds)
9for (i0 in 0 until holds1) {10 if (guard.compareAndSet(false, true)) {if (guard.compareAndSet(false, true))
9for (i in 0 until holds) {10 if (guardtrue.compareAndSet(false, true)) {11 acquired0++12 } else {13 blocked++status ← guarded
17 val status→ guarded = if (acquired1 == 0) {18 "idle"19 } else if (blocked0 > 0) {20 "blocked"21 } else {22 "guarded"23 }2425 println("holds=$holds1 acquired=$acquired1 blocked=$blocked0 $statusguarded")26}outputholds=1 acquired=1 blocked=0 guarded
holds ← 0, guard ← false, acquired ← 0, blocked ← 0, status ← idle
3fun main() {4 val holds→ 0 = 05 val guard→ false = AtomicBoolean(false)6 var acquired→ 0 = 07 var blocked→ 0 = 089 for (i in 0 until holds) {10 if (guard.compareAndSet(false, true)) {11 acquired++12 } else {13 blocked++14 }15 }1617 val status→ idle = if (acquired0 == 0) {18 "idle"19 } else if (blocked0 > 0) {20 "blocked"21 } else {22 "guarded"23 }2425 println("holds=$holds0 acquired=$acquired0 blocked=$blocked0 $statusidle")26}outputholds=0 acquired=0 blocked=0 idle
holds ← 2, guard ← false, acquired ← 0, blocked ← 0
3fun main() {4 val holds→ 2 = 25 val guard→ false = AtomicBoolean(false)6 var acquired→ 0 = 07 var blocked→ 0 = 0for (i in 0 until holds)
pass 1 of 29for (i0 in 0 until holds2) {10 if (guard.compareAndSet(false, true)) {if (guard.compareAndSet(false, true))
9for (i in 0 until holds) {10 if (guardtrue.compareAndSet(false, true)) {11 acquired0++12 } else {13 blocked++for (i in 0 until holds)
pass 2 of 29for (i1 in 0 until holds2) {10 if (guard.compareAndSet(false, true)) {else
11 acquired++12 } else {13 blocked0++14 }15}status ← blocked
17 val status→ blocked = if (acquired1 == 0) {18 "idle"19 } else if (blocked1 > 0) {20 "blocked"21 } else {22 "guarded"23 }2425 println("holds=$holds2 acquired=$acquired1 blocked=$blocked1 $statusblocked")26}outputholds=2 acquired=1 blocked=1 blocked