I want to run a function on a separate core. I wrote a script that runs it asynchronously in parallel two times.
const results = Channel()
function my_function()
delay = rand() * 5
@info "Task with $delay s"
@info "Thread $(Threads.threadid())"
sleep(delay)
put!(results, delay)
end
errormonitor(@async my_function())
errormonitor(@async my_function())
@info "returned $(take!(results))"
@info "returned $(take!(results))"
But both times in the same thread.
[ Info: Task with 2.9497522378270298 s
[ Info: Task with 4.956428193185428 s
[ Info: Thread 1
[ Info: Thread 1
[ Info: returned 2.9497522378270298
[ Info: returned 4.956428193185428
How can I run my_function
on different threads?
--threads
?