Skip to content

Instantly share code, notes, and snippets.

@cynddl
Created November 9, 2017 17:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cynddl/e694ae6e3eb99b732a89f1d3f797426f to your computer and use it in GitHub Desktop.
Save cynddl/e694ae6e3eb99b732a89f1d3f797426f to your computer and use it in GitHub Desktop.
addprocs(3)
type AtomicTask
category::Symbol
end
const jobs = RemoteChannel(()->Channel{AtomicTask}(Inf))
const results = RemoteChannel(()->Channel{Float64}(Inf))
@everywhere function execute_jobs(jobs, results)
while true
task = take!(jobs)
if task.category == :a
put!(jobs, AtomicTask(:b))
elseif task.category == :b
put!(jobs, AtomicTask(:c))
put!(jobs, AtomicTask(:c))
elseif task.category == :c
put!(results, rand())
end
end
end
# ---------------- ----------------
@schedule put!(jobs, AtomicTask(:a))
for p in workers()
remote_do(execute_jobs, p, jobs, results)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment