# How to realize this multithreading function

**URL:** <https://discourse.julialang.org/t/how-to-realize-this-multithreading-function/49537>\
**Category:** General Usage\
**Created:** [November 3, 2020, 3:27pm UTC](https://discourse.julialang.org/t/how-to-realize-this-multithreading-function/49537 "2020-11-03T15:27:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bluefog](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bluefog/32/19160_2.png) [@bluefog](https://discourse.julialang.org/u/bluefog)\
**Post date:** [November 3, 2020, 3:27pm UTC](https://discourse.julialang.org/t/how-to-realize-this-multithreading-function/49537/1 "2020-11-03T15:27:49Z")

</div>

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  
)  
)

---

<div class="post-metadata">

**Author:** ![pbayer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pbayer/32/11675_2.png) [@pbayer](https://discourse.julialang.org/u/pbayer)\
**Post date:** [November 3, 2020, 4:54pm UTC](https://discourse.julialang.org/t/how-to-realize-this-multithreading-function/49537/2 "2020-11-03T16:54:19Z")

</div>

would you please edit your post as described in

> [@Please read: make it easier to help you](https://discourse.julialang.org/t/psa-make-it-easier-to-help-you/14757):
>
> Welcome to the Julia Discourse! We are enthusiastic about helping Julia programmers, both beginner and experienced. This public service announcement (PSA) outlines best practices when asking for help. Following these points makes it easier for us to help you and more likely you’ll get a prompt, useful answer. Keywords are highlighted to make it easier to refer to specific points. Choose a descriptive title that captures the key part of your question, eg “plots with multiple axes” instead of …

---

<div class="post-metadata">

**Author:** ![bluefog](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bluefog/32/19160_2.png) [@bluefog](https://discourse.julialang.org/u/bluefog)\
**Post date:** [November 4, 2020, 1:07am UTC](https://discourse.julialang.org/t/how-to-realize-this-multithreading-function/49537/3 "2020-11-04T01:07:45Z")

</div>

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