How to realize this multithreading function

Core 1 is constantly calculating x, and core 2 is constantly taking the value of X

But did not debug through X, no shared program has been in the core 1 loop, please give me some advice, thank you

#========================================
using Distributed
using SharedArrays
x = SharedArray{Float64}(1, 1) #创建共享数组
addprocs(4)
@async (
fetch(
@spawnat 1 begin

while true
    x[1] = x[1] + 5.0  #1111111111
  # println("aaaa")
    sleep(1)
end

end
)
)

@async (
fetch(
@spawnat 2 begin
while true
if (mod(fetch(x[1]),20.0)==0.0) #2222222222222
println(fetch(x[1]))
end
sleep(1)
end
end
)
)

would you please edit your post as described in

1 Like

I’m sorry, because I don’t know how to operate for the first time, but the problem has been lifted. Thank you