Record arrivals counted down against a latch and report whether the barrier released.

Countdown Latch Coordination Report

CountdownLatchCoordinationReport.scala
import java.util.concurrent.atomic.AtomicInteger

object Main {
  def main(args: Array[String]): Unit = {
    val arrivals = 
    val needed = 3
    val latch = new AtomicInteger(needed)
    var counted = 0

    for (i <- 0 until arrivals) {
      latch.decrementAndGet()
      counted = counted + 1
    }

    val remaining = latch.get()

    var status = "partial"
    if (counted == 0) {
      status = "waiting"
    }
    if (remaining == 0) {
      status = "released"
    }

    println("arrivals=" + arrivals + " counted=" + counted + " remaining=" + remaining + " " + status)
  }
}
import java.util.concurrent.atomic.AtomicInteger

object Main {
  def main(args: Array[String]): Unit = {
    val arrivals = 
    val needed = 3
    val latch = new AtomicInteger(needed)
    var counted = 0

    for (i <- 0 until arrivals) {
      latch.decrementAndGet()
      counted = counted + 1
    }

    val remaining = latch.get()

    var status = "partial"
    if (counted == 0) {
      status = "waiting"
    }
    if (remaining == 0) {
      status = "released"
    }

    println("arrivals=" + arrivals + " counted=" + counted + " remaining=" + remaining + " " + status)
  }
}
import java.util.concurrent.atomic.AtomicInteger

object Main {
  def main(args: Array[String]): Unit = {
    val arrivals = 
    val needed = 3
    val latch = new AtomicInteger(needed)
    var counted = 0

    for (i <- 0 until arrivals) {
      latch.decrementAndGet()
      counted = counted + 1
    }

    val remaining = latch.get()

    var status = "partial"
    if (counted == 0) {
      status = "waiting"
    }
    if (remaining == 0) {
      status = "released"
    }

    println("arrivals=" + arrivals + " counted=" + counted + " remaining=" + remaining + " " + status)
  }
}
countdown latch A coordination report can record progress toward a barrier. An `AtomicInteger` started at a fixed count models a countdown latch, and each `decrementAndGet` records one arrival while `get` reports how many arrivals are still missing. With no arrivals the latch is still waiting, with some arrivals it is partial, and once the count reaches zero the barrier is released. The status line summarizes whether the latch stayed waiting, partial, or released after the recorded arrivals.