# How to share function f() arguments with Threads.@spawn?

**URL:** <https://discourse.julialang.org/t/how-to-share-function-f-arguments-with-threads-spawn/83627>\
**Category:** General Usage\
**Created:** [July 1, 2022, 2:37pm UTC](https://discourse.julialang.org/t/how-to-share-function-f-arguments-with-threads-spawn/83627 "2022-07-01T14:37:15Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![bienpierre](https://avatars.discourse-cdn.com/v4/letter/b/8c91f0/32.png) [@bienpierre](https://discourse.julialang.org/u/bienpierre)\
**Post date:** [July 1, 2022, 2:37pm UTC](https://discourse.julialang.org/t/how-to-share-function-f-arguments-with-threads-spawn/83627/1 "2022-07-01T14:37:15Z")

</div>

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

```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
julia> fetch(m1)
4

julia> fetch(m2)
8

julia> fetch(m3)
8

```

But with single thread :

```julia
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
