# RemoteChannel and usage of put! and take! on the same process

**URL:** https://discourse.julialang.org/t/remotechannel-and-usage-of-put-and-take-on-the-same-process/64525
**Category:** General Usage
**Tags:** parallel, distributed
**Created:** [July 12, 2021, 6:39pm UTC](https://discourse.julialang.org/t/remotechannel-and-usage-of-put-and-take-on-the-same-process/64525 "2021-07-12T18:39:24Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![deveshjawla](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/deveshjawla/32/16048_2.png) [@deveshjawla](https://discourse.julialang.org/u/deveshjawla)
#### Post date: [July 12, 2021, 6:39pm UTC](https://discourse.julialang.org/t/remotechannel-and-usage-of-put-and-take-on-the-same-process/64525/1 "2021-07-12T18:39:25Z")

</div>

```julia
using Distributed

addprocs(2, exeflags="--project")

@everywhere begin

function update_remote_counter(remote_counter::RemoteChannel, update_count::Int)

old_value=take!(remote_counter)

put!(remote_counter, old_value + update_count)

return nothing

end

function uses_ts(training_step)

training_step_ = 0

while training_step_ < 10000

training_step_ = fetch(training_step)

println("From user", training_step_)

end

return true

end

function changes_ts(training_step)

training_step_ = 0

while training_step_ < 10000

training_step_ += 1

update_remote_counter(training_step, 1)

println("From changer", training_step_)

end

return true

end

end

training_step = RemoteChannel(()->Channel{Int}(1))

put!(training_step, 0)

u = @spawnat :any uses_ts(training_step)

c = @spawnat :any changes_ts(training_step)

```

Here is a MWE of my code for the MuZero algorithm at the [link](https://github.com/deveshjawla/MuZero.jl/blob/main/games/tictactoe/main.jl).

In the example the line `update_remote_counter(training_step, 1)` executes successfully until the last iteration. However in the original code, it is a bottleneck after some iterations. I have checked this using `println` just before and the after this line. The code prints before the line but is waiting for `RemoteChannel training_step` to receive a value.

Does anyone know why this is happening?
