When I run the following code, it runs as expected (that is, it outputs both "endless loop" and "loop in 100"):
@async while true
print("endless loop\n")
end
for i in 1:100
print("loop in 100\n")
end
However, for some reason, when I changed print to println, the result was very different
@async while true
println("endless loop")
end
for i in 1:100
println("loop in 100")
end
This code only outputs "loop in 100" a hundred times. Any ideas why?
Actually, println seems to always impact multithread execution:
## works as expected, prints "loop in 100" 100 times and "endless loop" 3 times in between
@async while true
print("endless loop\n")
end
@sync for i in 1:100
@async print("loop in 100\n")
end
## simply switching to println makes a program that outputs "endless loop" forever
@async while true
println("endless loop")
end
@sync for i in 1:100
@async println("loop in 100")
end
I used println for debug output but then realised it's unusable for that purposes. Any suggestion why exactly this works the way it works would be very helpful. I'm executing it with Julia 1.6.1 so that I can use automatic thread detection julia -t auto file.jl.