CountDownLatches.jl

A simple multithreading primitive.
Author Octogonapus
Popularity
5 Stars
Updated Last
2 Years Ago
Started In
March 2021

CountDownLatches

Stable Dev Build Status Coverage Code Style: Blue

This package implements a multithreading primitive called a CountDownLatch that holds an internal count. The latch's count can be decremented by multiple threads. Threads may also wait on the latch's count to become zero.

Example

In this example, the main thread will be blocked by await until the spawned thread counts the latch down. This is clearly a contrived example, but imagine that there is much more code before count_down and before await.

latch = CountDownLatch(1)

Threads.@spawn begin
    # Decrease the latch's count by one
    count_down(latch)
end

# Wait until the latch's count become zero
await(latch)

Required Packages

No packages found.

Used By Packages