Say we have a struct Foo:
mutable struct Foo
dee::Int
fee::Int = 3
end
We then define an array of Foo’s
arrFoo = [Foo(1), Foo(1), Foo(2), Foo(3)]
Then we have a function that, when given foo and a specific item of Foo, modifies dee, but only looks at fee:
function modifyFoo(a::Foo, arr, index::Int)
for t in arr
a.dee += t.fee
end
arr[index] = a
end
Then we iterate over arrFoo, using multiple threads:
i = 1
Threads.@threads for item in arrFoo
modifyFoo(item, arrFoo, i)
i += 1
end
Does this situation create a data race? I don’t think it should, but I’m a bit nervous about it, considering that it is reading and writing to the same struct – just not the same items. Any comments clearing up how data races work are much appreciated.