Skip to content

Commit

Permalink
Added minimal code example to Channels, fix #14312
Browse files Browse the repository at this point in the history
  • Loading branch information
kshyatt committed Jul 28, 2016
1 parent e18ae9e commit aee9adb
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions doc/manual/parallel-computing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,27 @@ and size 10. The channel exists on worker ``pid``\ .
Methods ``put!``\ , ``take!``\ , ``fetch``\ , ``isready`` and ``wait`` on a ``RemoteChannel`` are proxied onto
the backing store on the remote process.

As an example, we can construct a ``RemoteChannel`` to a worker, ``put!``\ an index inside, then ``take!``\ it out::
addprocs(5)
worker_pool = Base.default_worker_pool()
channels = [RemoteChannel() for i in 1:nworkers()] #every worker gets its own channel
for (i,c) in enumerate(channels)
put!(c, i)
end

for c in channels
@show take!(c)
end

If we run this, we will see::

take!(c) = 1
take!(c) = 2
take!(c) = 3
take!(c) = 4
take!(c) = 5

``RemoteChannel`` can thus be used to refer to user implemented ``AbstractChannel`` objects. A simple
example of this is provided in ``examples/dictchannel.jl`` which uses a dictionary as its remote store.

Expand Down

0 comments on commit aee9adb

Please sign in to comment.