I have the following code:
const vec = rand(10000) const shouldrun = Ref(true) uselessalgo(vec) = vec .= rand(10000) function uselessLoop(vec, shouldrun) while shouldrun uselessalgo(vec) GC.safepoint() end end function spawnUselessLoop(vec, shouldrun) println("Starting loop...") shouldrun = true println("Spawning thread...") Threads.@spawn uselessLoop(vec, shouldrun) println("Sleeping") sleep(1) println("Stopping loop...") shouldrun = false end spawnUselessLoop(vec, shouldrun)
If I save this as a file and run it through
include("filename"), then it will almost certainly hang for me. First of all, I’m not sure exactly why, I thought
GC.safepoint() should prevent this. Can anybody explain this to me?
Then, if I first comment out the function call, and manually call it by typing it in in the REPL, it will almost never hang for me. Why does there seem to be a difference?