Internal

Warning

Everything on this page is internal and and might changed or dropped at any point!

References

OhMyThreads.Tools.SimpleBarrierType

SimpleBarrier(n::Integer)

Simple reusable barrier for n parallel tasks.

Given b = SimpleBarrier(n) and n parallel tasks, each task that calls wait(b) will block until the other n-1 tasks have called wait(b) as well.

Example

n = nthreads()
barrier = SimpleBarrier(n)
@sync for i in 1:n
    @spawn begin
        println("A")
        wait(barrier) # synchronize all tasks
        println("B")
        wait(barrier) # synchronize all tasks (reusable)
        println("C")
    end
end
source
OhMyThreads.Tools.taskidMethod
taskid() :: UInt

Return a UInt identifier for the current running Task. This identifier will be unique so long as references to the task it came from still exist.

source
OhMyThreads.Tools.try_enter!Method
try_enter!(f, s::OnlyOneRegion)

When called from multiple parallel tasks (on a shared s::OnlyOneRegion) only a single task will execute f.

Example

using OhMyThreads: @tasks
using OhMyThreads.Tools: OnlyOneRegion, try_enter!

only_one = OnlyOneRegion()

@tasks for i in 1:10
    @set ntasks = 10

    println(i, ": before")
    try_enter!(only_one) do
        println(i, ": only printed by a single task")
        sleep(1)
    end
    println(i, ": after")
end
source