Internal
Everything on this page is internal and and might changed or dropped at any point!
References
OhMyThreads.Tools.OnlyOneRegion — TypeMay be used to mark a region in parallel code to be executed by a single task only (all other tasks shall skip over it).
See try_enter! and reset!.
OhMyThreads.Tools.SimpleBarrier — TypeSimpleBarrier(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
endOhMyThreads.Tools.nthtid — Methodnthtid(n)Returns the thread id of the nth Julia thread in the :default threadpool.
OhMyThreads.Tools.reset! — MethodReset the OnlyOneRegion (so that it can be used again).
OhMyThreads.Tools.taskid — Methodtaskid() :: UIntReturn 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.
OhMyThreads.Tools.try_enter! — Methodtry_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