Skip to content

Commit

Permalink
rename put and take to put! and take! (fixes #5511)
Browse files Browse the repository at this point in the history
make put! return its first argument (fixes #5819)
  • Loading branch information
JeffBezanson committed Feb 18, 2014
1 parent b81df54 commit f017133
Show file tree
Hide file tree
Showing 13 changed files with 58 additions and 48 deletions.
9 changes: 9 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,12 @@ Deprecated or removed

* `nnz` is removed. Use `countnz` or `nfilled` instead ([#5538])

* `setfield` is renamed `setfield!` ([#5748])

* `put` and `take` are renamed `put!` and `take!` ([#5511])

* `put!` now returns its first argument, the remote reference ([#5819])

[#4042]: https://github.com/JuliaLang/julia/issues/4042
[#5164]: https://github.com/JuliaLang/julia/issues/5164
[#4026]: https://github.com/JuliaLang/julia/issues/4026
Expand Down Expand Up @@ -253,6 +259,9 @@ Deprecated or removed
[#5576]: https://github.com/JuliaLang/julia/pull/5576
[#5703]: https://github.com/JuliaLang/julia/pull/5703
[#5427]: https://github.com/JuliaLang/julia/pull/5427
[#5748]: https://github.com/JuliaLang/julia/issues/5748
[#5511]: https://github.com/JuliaLang/julia/issues/5511
[#5819]: https://github.com/JuliaLang/julia/issues/5819

Julia v0.2.0 Release Notes
==========================
Expand Down
6 changes: 3 additions & 3 deletions base/client.jl
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ end
function repl_callback(ast::ANY, show_value)
global _repl_enough_stdin = true
stop_reading(STDIN)
put(repl_channel, (ast, show_value))
put!(repl_channel, (ast, show_value))
end

_eval_done = Condition()
Expand All @@ -161,7 +161,7 @@ function run_repl()
wait(_eval_done)
end
end
put(repl_channel,(nothing,-1))
put!(repl_channel,(nothing,-1))
end

while true
Expand All @@ -173,7 +173,7 @@ function run_repl()
ccall(:repl_callback_enable, Void, (Ptr{Uint8},), prompt_string)
global _repl_enough_stdin = false
start_reading(STDIN)
(ast, show_value) = take(repl_channel)
(ast, show_value) = take!(repl_channel)
if show_value == -1
# exit flag
break
Expand Down
2 changes: 1 addition & 1 deletion base/darray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ drandn(d::Int...) = drandn(d)
function distribute(a::AbstractArray)
owner = myid()
rr = RemoteRef()
put(rr, a)
put!(rr, a)
DArray(size(a)) do I
remotecall_fetch(owner, ()->fetch(rr)[I...])
end
Expand Down
2 changes: 2 additions & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,8 @@ eval(Sys, :(@deprecate shlib_list dllist))
@deprecate myindexes localindexes

@deprecate setfield setfield!
@deprecate put put!
@deprecate take take!

# 0.3 discontinued functions

Expand Down
4 changes: 2 additions & 2 deletions base/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1120,12 +1120,12 @@ export
nworkers,
pmap,
procs,
put,
put!,
remotecall,
remotecall_fetch,
remotecall_wait,
rmprocs,
take,
take!,
timedwait,
wait,
workers,
Expand Down
2 changes: 1 addition & 1 deletion base/loading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ function reload_path(path::String)
end
end
if !isready(package_locks[path])
put(package_locks[path],nothing)
put!(package_locks[path],nothing)
end
nothing
end
Expand Down
34 changes: 18 additions & 16 deletions base/multi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
##
## RemoteRef(p) - ...or on a particular processor
##
## put(r, val) - store a value to an uninitialized RemoteRef
## put!(r, val) - store a value to an uninitialized RemoteRef
##
## @spawn expr -
## evaluate expr somewhere. returns a RemoteRef. all variables in expr
Expand All @@ -42,8 +42,8 @@

# todo:
# - more indexing
# * take() to empty a Ref (full/empty variables)
# * have put() wait on non-empty Refs
# * take!() to empty a Ref (full/empty variables)
# * have put!() wait on non-empty Refs
# - removing nodes
# - more dynamic scheduling
# * fetch/wait latency seems to be excessive
Expand Down Expand Up @@ -554,7 +554,7 @@ function wait_empty(rv::RemoteValue)
return nothing
end

## core messages: do, call, fetch, wait, ref, put ##
## core messages: do, call, fetch, wait, ref, put! ##


function run_work_thunk(thunk)
Expand All @@ -569,7 +569,8 @@ function run_work_thunk(thunk)
result
end
function run_work_thunk(rv::RemoteValue, thunk)
put(rv, run_work_thunk(thunk))
put!(rv, run_work_thunk(thunk))
nothing
end

function schedule_call(rid, thunk)
Expand Down Expand Up @@ -701,17 +702,18 @@ fetch(r::RemoteRef) = call_on_owner(fetch_ref, r)
fetch(x::ANY) = x

# storing a value to a Ref
function put(rv::RemoteValue, val::ANY)
function put!(rv::RemoteValue, val::ANY)
wait_empty(rv)
rv.result = val
rv.done = true
notify_full(rv)
rv
end

put_ref(rid, v) = put(lookup_ref(rid), v)
put(rr::RemoteRef, val::ANY) = (call_on_owner(put_ref, rr, val); val)
put_ref(rid, v) = put!(lookup_ref(rid), v)
put!(rr::RemoteRef, val::ANY) = (call_on_owner(put_ref, rr, val); rr)

function take(rv::RemoteValue)
function take!(rv::RemoteValue)
wait_full(rv)
val = rv.result
rv.done = false
Expand All @@ -720,8 +722,8 @@ function take(rv::RemoteValue)
val
end

take_ref(rid) = take(lookup_ref(rid))
take(rr::RemoteRef) = call_on_owner(take_ref, rr)
take_ref(rid) = take!(lookup_ref(rid))
take!(rr::RemoteRef) = call_on_owner(take_ref, rr)

function deliver_result(sock::IO, msg, oid, value)
#print("$(myid()) sending result $oid\n")
Expand Down Expand Up @@ -815,7 +817,7 @@ function create_message_handler_loop(sock::AsyncStream) #returns immediately
oid = deserialize(sock)
#print("$(myid()) got $msg $oid\n")
val = deserialize(sock)
put(lookup_ref(oid), val)
put!(lookup_ref(oid), val)
elseif is(msg, :identify_socket)
otherid = deserialize(sock)
register_worker(Worker("", 0, sock, otherid))
Expand Down Expand Up @@ -1464,14 +1466,14 @@ function timedwait(testcb::Function, secs::Float64; pollint::Float64=0.1)
timercb(aw, status) = begin
try
if testcb()
put(done, :ok)
put!(done, :ok)
elseif (time() - start) > secs
put(done, :timed_out)
put!(done, :timed_out)
elseif status != 0
put(done, :error)
put!(done, :error)
end
catch e
put(done, :error)
put!(done, :error)
finally
isready(done) && stop_timer(aw)
end
Expand Down
6 changes: 3 additions & 3 deletions doc/stdlib/base.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4513,11 +4513,11 @@ Parallel Computing

Perform ``fetch(remotecall(...))`` in one message.

.. function:: put(RemoteRef, value)
.. function:: put!(RemoteRef, value)

Store a value to a remote reference. Implements "shared queue of length 1" semantics: if a value is already present, blocks until the value is removed with ``take``.
Store a value to a remote reference. Implements "shared queue of length 1" semantics: if a value is already present, blocks until the value is removed with ``take``. Returns its first argument.

.. function:: take(RemoteRef)
.. function:: take!(RemoteRef)

Fetch the value of a remote reference, removing it so that the reference is empty again.

Expand Down
6 changes: 3 additions & 3 deletions test/file.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,14 @@ rmdir(b_tmpdir)
#######################################################################
function test_file_poll(channel,timeout_s)
rc = poll_file(file, iround(timeout_s/10), timeout_s)
put(channel,rc)
put!(channel,rc)
end

function test_timeout(tval)
tic()
channel = RemoteRef()
@async test_file_poll(channel,tval)
tr = take(channel)
tr = take!(channel)
t_elapsed = toq()
@test !tr
@test tval <= t_elapsed
Expand All @@ -83,7 +83,7 @@ function test_touch(slval)
f = open(file,"a")
write(f,"Hello World\n")
close(f)
tr = take(channel)
tr = take!(channel)
@test tr
end

Expand Down
12 changes: 6 additions & 6 deletions test/iterators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@ macro test_buildvec(ex...)
:(@test buildvec($(ex[1])) == $(ex[2]))
end

@test_buildvec take(count(), 0) []
@test_buildvec take(count(), 5) [0:4]
@test_buildvec take(count(1,3), 5) [1:3:13]
@test_buildvec take(count(zeros(2,2)), 3) [i * eye(2) for i=0:2]
@test_buildvec take!(count(), 0) []
@test_buildvec take!(count(), 5) [0:4]
@test_buildvec take!(count(1,3), 5) [1:3:13]
@test_buildvec take!(count(zeros(2,2)), 3) [i * eye(2) for i=0:2]

@test_buildvec drop(1:5, 5) []
@test_buildvec drop(1:0, 0) []
@test_buildvec drop(1:5, 2) [3:5]

@test_buildvec cycle(1:0) []
@test_buildvec take(cycle(1:3), 8) [1:3,1:3,1:2]
@test_buildvec take!(cycle(1:3), 8) [1:3,1:3,1:2]

@test_buildvec repeat('a', 0) []
@test_buildvec repeat('a', 5) ['a' for i = 1:5]
@test_buildvec take(repeat('a'), 5) ['a' for i = 1:5]
@test_buildvec take!(repeat('a'), 5) ['a' for i = 1:5]

@test_buildvec chain() []
@test_buildvec chain(1:0) []
Expand Down
15 changes: 6 additions & 9 deletions test/netload/ltests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ rr_sent = RemoteRef()
end
# println("process $(myid()) received $bread bytes")
close(s)
put(rr_rcd, true)
put!(rr_rcd, true)
end
end)

Expand All @@ -67,7 +67,7 @@ rr_sent = RemoteRef()
end
close(s)
# println("process $(myid()) sent $bwritten bytes")
put(rr_sent, true)
put!(rr_sent, true)
end)

wait(rr_rcd)
Expand All @@ -93,22 +93,19 @@ rr_client = RemoteRef()
begin
while (true)
s=accept(server)
@async begin xfer(s, xfer_exp); put(rr_server, true); take(rr_client); close(s); put(rr_server, true); end
@async begin xfer(s, xfer_exp); put!(rr_server, true); take!(rr_client); close(s); put!(rr_server, true); end
end
end)



@spawnat(workers()[1], begin s = connect("localhost", port); xfer(s, xfer_exp); put(rr_client, true); take(rr_server); close(s); put(rr_client, true); end)
@spawnat(workers()[1], begin s = connect("localhost", port); xfer(s, xfer_exp); put!(rr_client, true); take!(rr_server); close(s); put!(rr_client, true); end)

take(rr_server)
take(rr_client)
take!(rr_server)
take!(rr_client)

close(server)

println(" : OK")

@unix_only include("memtest.jl")



6 changes: 3 additions & 3 deletions test/parallel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ rr1 = RemoteRef()
rr2 = RemoteRef()
rr3 = RemoteRef()

@async begin sleep(0.5); put(rr1, :ok) end
@async begin sleep(1.0); put(rr2, :ok) end
@async begin sleep(2.0); put(rr3, :ok) end
@async begin sleep(0.5); put!(rr1, :ok) end
@async begin sleep(1.0); put!(rr2, :ok) end
@async begin sleep(2.0); put!(rr3, :ok) end

tic()
timedwait(1.0) do
Expand Down
2 changes: 1 addition & 1 deletion test/spawn.jl
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ end
yield()
schedule(t, InterruptException(), error=true)
yield()
put(r,11)
put!(r,11)
yield()


Expand Down

2 comments on commit f017133

@ivarne
Copy link
Member

@ivarne ivarne commented on f017133 Feb 21, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The noisy deprecations here cause trouble in https://github.com/loladiro/REPL.jl, because printing the warning garbles the output.

I opened a PR Keno/REPL.jl#38, but that will break compatibility with our latest official release for NO reason. As our deprecation policy states that this deprecation will have to stand until 0.4 is released anyway, so maybe we could have this deprecation to be silent until right before we release 0.3?

@JeffBezanson
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only way to fix this is to release a new version of REPL.jl.

Please sign in to comment.