# Share object between master/workers

**URL:** https://discourse.julialang.org/t/share-object-between-master-workers/1098
**Category:** General Usage
**Created:** [December 21, 2016, 8:47pm UTC](https://discourse.julialang.org/t/share-object-between-master-workers/1098 "2016-12-21T20:47:45Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![evanfields](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/evanfields/32/1744_2.png) [@evanfields](https://discourse.julialang.org/u/evanfields)
#### Post date: [December 21, 2016, 8:47pm UTC](https://discourse.julialang.org/t/share-object-between-master-workers/1098/1 "2016-12-21T20:47:45Z")

</div>

Is there a way to share an instance of a non-bits type between the master process and one or more workers? I’d like to do something like the following:

```julia
addprocs(1)
@everywhere MyType
   x
end
@everywhere function print_x_twice(mt::MyType)
    println(mt.x)
    sleep(5)
    println(mt.x)
end

mt = MyType(1)
shared_ref = SharedRef(mt)

@spawnat 2 begin
    mt = get(SharedRef)
    print_x_twice(mt)
end

sleep(.1)
mt.x = 100

```

and see output of

```julia
From worker 2: 1
From worker 2: 100

```

ie., I’d like changes made to `mt` on the master process to be visible on the worker. Of course, `SharedRef` isn’t a real type. Is there a way to do this? I’d think `RemoteChannel`, but I’ve read through the parallelism documentation half a dozen times and still don’t really understand how to use remote channels; certainly I haven’t been able to get the above working with a remote channel.

---

<div class="post-metadata">

### Author: ![evanfields](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/evanfields/32/1744_2.png) [@evanfields](https://discourse.julialang.org/u/evanfields)
#### Post date: [December 22, 2016, 1:05am UTC](https://discourse.julialang.org/t/share-object-between-master-workers/1098/2 "2016-12-22T01:05:35Z")

</div>

Self-reply: I am still curious about how to do this because it seems like it could be useful. In the mean time, passing messages via `RemoteChannel` seems to work. Something like

```julia
rr = RemoteChannel()
x = ObjectWithRemoteChannel(rr)
@spawn dostuff(x)

push!(rr, message) # visible on the worker

```

---

<div class="post-metadata">

### Author: ![Mattriks](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mattriks/32/351_2.png) [@Mattriks](https://discourse.julialang.org/u/Mattriks)
#### Post date: [December 22, 2016, 2:22am UTC](https://discourse.julialang.org/t/share-object-between-master-workers/1098/3 "2016-12-22T02:22:39Z")

</div>

I’m not familiar with sharing objects, but for passing objects see also [`ParallelDataTransfer`](https://github.com/ChrisRackauckas/ParallelDataTransfer.jl).
