Skip to content

Commit

Permalink
Merge pull request #12466 from JuliaLang/amitm/parametric_rr
Browse files Browse the repository at this point in the history
RemoteRefs parameterized on remote store type
  • Loading branch information
amitmurthy committed Aug 7, 2015
2 parents 9af0144 + 5b8b52f commit b15733f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
13 changes: 6 additions & 7 deletions base/multi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ end

const client_refs = WeakKeyDict()

type RemoteRef
type RemoteRef{RemoteStore}
where::Int
whence::Int
id::Int
Expand Down Expand Up @@ -488,14 +488,13 @@ end

RemoteRef(w::LocalProcess) = RemoteRef(w.id)
RemoteRef(w::Worker) = RemoteRef(w.id)
RemoteRef(pid::Integer=myid()) = RemoteRef(pid, myid(), next_ref_id())
RemoteRef(pid::Integer=myid()) = RemoteRef(def_rv_channel, pid)

function RemoteRef(f::Function, pid::Integer=myid())
remotecall_fetch(pid, f-> begin
rr = RemoteRef()
lookup_ref(rr2id(rr), f)
rr
end, f)
remotecall_fetch(pid, (f, rrid) -> begin
rv=lookup_ref(rrid, f)
RemoteRef{typeof(rv.c)}(myid(), rrid[1], rrid[2])
end, f, next_rrid_tuple())
end

hash(r::RemoteRef, h::UInt) = hash(r.whence, hash(r.id, h))
Expand Down
1 change: 1 addition & 0 deletions test/examples.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ pid = length(w_set) > 0 ? w_set[1] : myid()

remotecall_fetch(pid, f->(include(f); nothing), dc_path)
dc=RemoteRef(()->DictChannel(), pid)
@test typeof(dc) == RemoteRef{DictChannel}

@test isready(dc) == false
put!(dc, 1, 2)
Expand Down
2 changes: 2 additions & 0 deletions test/parallel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ id_other = filter(x -> x != id_me, procs())[rand(1:(nprocs()-1))]
@fetch begin myid() end

rr=RemoteRef()
@test typeof(rr) == RemoteRef{Channel{Any}}
a = rand(5,5)
put!(rr, a)
@test rr[2,3] == a[2,3]
@test rr[] == a

rr=RemoteRef(workers()[1])
@test typeof(rr) == RemoteRef{Channel{Any}}
a = rand(5,5)
put!(rr, a)
@test rr[1,5] == a[1,5]
Expand Down

0 comments on commit b15733f

Please sign in to comment.