On Fri, Oct 7, 2016 at 4:02 PM, Diego Javier Zea <diego...@gmail.com> wrote: > Hi, > I was starting to play with Threads.@threads and I noticed a strange > behaviour when the macro is used together with throw and ErrorException: > > | | |_| | | | (_| | | Version 0.5.0 (2016-09-19 18:14 UTC) > _/ |\__'_|_|_|\__'_| | Official http://julialang.org/ release > |__/ | x86_64-pc-linux-gnu > > julia> a = zeros(10); > > julia> Threads.@threads for i = 1:10 > a[i] = Threads.threadid() > if 4 <= i <= 8 > throw(ErrorException("My Error")) > end > end > > julia> a > 10-element Array{Float64,1}: > 1.0 > 1.0 > 1.0 > 2.0 > 0.0 > 0.0 > 3.0 > 0.0 > 4.0 > 4.0 > > julia> a = zeros(10); > > julia> Threads.@threads for i = 1:10 > if 4 <= i <= 8 > throw(ErrorException("My Error")) > end > a[i] = Threads.threadid() > end > > julia> a > 10-element Array{Float64,1}: > 1.0 > 1.0 > 1.0 > 0.0 > 0.0 > 0.0 > 0.0 > 0.0 > 4.0 > 4.0 > > The loop isn't terminated with the error and there is not error message > printed. When the throw is at the end of the loop body, the result looks > strange and unpredictable. > Is this behaviour expected?
It's known and we have an issue for it already. > Do I simply need to avoid using throw and threads together? For now. Yes. And unless you are working on threading support in Base julia you should avoid using threads in general. > > Best, >