Dear all,
First of all, sorry if element has been questioned before.
I have the following code with multi-threads ($ julia --threads=4 when launching Julia ): :
import Base.Threads.@spawn
mutable struct MyStructTest
a::Int
end
function test_spawn(nn::MyStructTest)
#do some stuff related to nn.a
return nn.a
end
m = MyStructTest(4);
m1 = Threads.@spawn test_spawn(m);
m.a = 6;
m2 = Threads.@spawn test_spawn(m);
m.a = 8;
m3 = Threads.@spawn test_spawn(m);
fetch(m1)
fetch(m2)
fetch(m3)
and it produces:
julia> fetch(m1)
4
julia> fetch(m2)
8
julia> fetch(m3)
8
But with single thread :
julia> fetch(m1)
4
julia> fetch(m2)
6
julia> fetch(m3)
8
I am asking how to be sure that m1 is 4, m2 is 6 and m3 is 8 with multi-threading?
Warmest regards