# Waiting on a Remote Condition

**URL:** <https://discourse.julialang.org/t/waiting-on-a-remote-condition/20170>\
**Category:** Julia at Scale\
**Tags:** question\
**Created:** [January 28, 2019, 5:33am UTC](https://discourse.julialang.org/t/waiting-on-a-remote-condition/20170 "2019-01-28T05:33:52Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![rohanmclure](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rohanmclure/32/5912_2.png) [@rohanmclure](https://discourse.julialang.org/u/rohanmclure)\
**Post date:** [January 28, 2019, 5:33am UTC](https://discourse.julialang.org/t/waiting-on-a-remote-condition/20170/1 "2019-01-28T05:33:52Z")

</div>

I’m hoping to use Conditions to synchronise communication between a master and worker process.

The `notify` function will wake up only the tasks that are already waiting on a condition. If we do not know which of the following remote calls will occur first, it is possible for the following code to not terminate.

```julia
using Distributed
addprocs(1)
@fetchfrom 2 begin
    global condition = Condition()
end

@sync begin
    @async remotecall_wait(2) do
        notify(condition)
    end
    @async remotecall_wait(2) do
        wait(condition)
    end
end

```

From my understanding, termination is guaranteed where instead we use:

```julia
@sync begin
    @async begin
        yield()
        remotecall_wait(2) do
            notify(condition)
        end
    end
    @async remotecall_wait(2) do
        wait(condition)
    end
end

```

In the more general case where these remote calls occur at entirely different times to one another, termination should still be reached (with matching invocations of `notify` and `wait`), even if the `notify` call occurs and yields before the `wait` call is even initiated.

Should I be using a different tool to Conditions for this use case?  
Thanks
