I'm trying to specify to run tasks on specific threads such that I can use two threads dedicated to a time consuming task that "put" to a channel and the others to processing that.
I’m stuck at how to assign a specific task to a specific thread. I thought I could use something like @spawnat but that does not seem to work. I wrote the code below to illustrate what I want to achieve
channel = Channel{Tuple{Int64, Int64}}(1000)
function stream()
# won't actually use this later, but
# easier to see what threads are used
for new_item in channel
println(new_item)
end
end
function cool_function(x::Int64)
sleep(1)
data = (Threads.threadid(), ~(x)+1)
put!(channel, data)
end
function spawner(x::Array{Int64})
for (i, number) in enumerate(x)
if iseven(i)
# Add to queue for thread X
Threads.@spawn cool_function(i)
else
# Add to queue for thread Y
Threads.@spawn cool_function(i)
end
end
end
@async stream()
spawner([1,2,3,4,5])
Any ideas on how to add tasks to a specific thread queue in spawner? :). Like "add to queue of thread1"