Skip to content

Commit f017133

Browse files
committedFeb 18, 2014
rename put and take to put! and take! (fixes JuliaLang#5511)
make put! return its first argument (fixes JuliaLang#5819)
1 parent b81df54 commit f017133

13 files changed

+58
-48
lines changed
 

‎NEWS.md

+9
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,12 @@ Deprecated or removed
199199

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

202+
* `setfield` is renamed `setfield!` ([#5748])
203+
204+
* `put` and `take` are renamed `put!` and `take!` ([#5511])
205+
206+
* `put!` now returns its first argument, the remote reference ([#5819])
207+
202208
[#4042]: https://github.com/JuliaLang/julia/issues/4042
203209
[#5164]: https://github.com/JuliaLang/julia/issues/5164
204210
[#4026]: https://github.com/JuliaLang/julia/issues/4026
@@ -253,6 +259,9 @@ Deprecated or removed
253259
[#5576]: https://github.com/JuliaLang/julia/pull/5576
254260
[#5703]: https://github.com/JuliaLang/julia/pull/5703
255261
[#5427]: https://github.com/JuliaLang/julia/pull/5427
262+
[#5748]: https://github.com/JuliaLang/julia/issues/5748
263+
[#5511]: https://github.com/JuliaLang/julia/issues/5511
264+
[#5819]: https://github.com/JuliaLang/julia/issues/5819
256265

257266
Julia v0.2.0 Release Notes
258267
==========================

‎base/client.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ end
140140
function repl_callback(ast::ANY, show_value)
141141
global _repl_enough_stdin = true
142142
stop_reading(STDIN)
143-
put(repl_channel, (ast, show_value))
143+
put!(repl_channel, (ast, show_value))
144144
end
145145

146146
_eval_done = Condition()
@@ -161,7 +161,7 @@ function run_repl()
161161
wait(_eval_done)
162162
end
163163
end
164-
put(repl_channel,(nothing,-1))
164+
put!(repl_channel,(nothing,-1))
165165
end
166166

167167
while true
@@ -173,7 +173,7 @@ function run_repl()
173173
ccall(:repl_callback_enable, Void, (Ptr{Uint8},), prompt_string)
174174
global _repl_enough_stdin = false
175175
start_reading(STDIN)
176-
(ast, show_value) = take(repl_channel)
176+
(ast, show_value) = take!(repl_channel)
177177
if show_value == -1
178178
# exit flag
179179
break

‎base/darray.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ drandn(d::Int...) = drandn(d)
160160
function distribute(a::AbstractArray)
161161
owner = myid()
162162
rr = RemoteRef()
163-
put(rr, a)
163+
put!(rr, a)
164164
DArray(size(a)) do I
165165
remotecall_fetch(owner, ()->fetch(rr)[I...])
166166
end

‎base/deprecated.jl

+2
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,8 @@ eval(Sys, :(@deprecate shlib_list dllist))
392392
@deprecate myindexes localindexes
393393

394394
@deprecate setfield setfield!
395+
@deprecate put put!
396+
@deprecate take take!
395397

396398
# 0.3 discontinued functions
397399

‎base/exports.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -1120,12 +1120,12 @@ export
11201120
nworkers,
11211121
pmap,
11221122
procs,
1123-
put,
1123+
put!,
11241124
remotecall,
11251125
remotecall_fetch,
11261126
remotecall_wait,
11271127
rmprocs,
1128-
take,
1128+
take!,
11291129
timedwait,
11301130
wait,
11311131
workers,

‎base/loading.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ function reload_path(path::String)
151151
end
152152
end
153153
if !isready(package_locks[path])
154-
put(package_locks[path],nothing)
154+
put!(package_locks[path],nothing)
155155
end
156156
nothing
157157
end

‎base/multi.jl

+18-16
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
##
2525
## RemoteRef(p) - ...or on a particular processor
2626
##
27-
## put(r, val) - store a value to an uninitialized RemoteRef
27+
## put!(r, val) - store a value to an uninitialized RemoteRef
2828
##
2929
## @spawn expr -
3030
## evaluate expr somewhere. returns a RemoteRef. all variables in expr
@@ -42,8 +42,8 @@
4242

4343
# todo:
4444
# - more indexing
45-
# * take() to empty a Ref (full/empty variables)
46-
# * have put() wait on non-empty Refs
45+
# * take!() to empty a Ref (full/empty variables)
46+
# * have put!() wait on non-empty Refs
4747
# - removing nodes
4848
# - more dynamic scheduling
4949
# * fetch/wait latency seems to be excessive
@@ -554,7 +554,7 @@ function wait_empty(rv::RemoteValue)
554554
return nothing
555555
end
556556

557-
## core messages: do, call, fetch, wait, ref, put ##
557+
## core messages: do, call, fetch, wait, ref, put! ##
558558

559559

560560
function run_work_thunk(thunk)
@@ -569,7 +569,8 @@ function run_work_thunk(thunk)
569569
result
570570
end
571571
function run_work_thunk(rv::RemoteValue, thunk)
572-
put(rv, run_work_thunk(thunk))
572+
put!(rv, run_work_thunk(thunk))
573+
nothing
573574
end
574575

575576
function schedule_call(rid, thunk)
@@ -701,17 +702,18 @@ fetch(r::RemoteRef) = call_on_owner(fetch_ref, r)
701702
fetch(x::ANY) = x
702703

703704
# storing a value to a Ref
704-
function put(rv::RemoteValue, val::ANY)
705+
function put!(rv::RemoteValue, val::ANY)
705706
wait_empty(rv)
706707
rv.result = val
707708
rv.done = true
708709
notify_full(rv)
710+
rv
709711
end
710712

711-
put_ref(rid, v) = put(lookup_ref(rid), v)
712-
put(rr::RemoteRef, val::ANY) = (call_on_owner(put_ref, rr, val); val)
713+
put_ref(rid, v) = put!(lookup_ref(rid), v)
714+
put!(rr::RemoteRef, val::ANY) = (call_on_owner(put_ref, rr, val); rr)
713715

714-
function take(rv::RemoteValue)
716+
function take!(rv::RemoteValue)
715717
wait_full(rv)
716718
val = rv.result
717719
rv.done = false
@@ -720,8 +722,8 @@ function take(rv::RemoteValue)
720722
val
721723
end
722724

723-
take_ref(rid) = take(lookup_ref(rid))
724-
take(rr::RemoteRef) = call_on_owner(take_ref, rr)
725+
take_ref(rid) = take!(lookup_ref(rid))
726+
take!(rr::RemoteRef) = call_on_owner(take_ref, rr)
725727

726728
function deliver_result(sock::IO, msg, oid, value)
727729
#print("$(myid()) sending result $oid\n")
@@ -815,7 +817,7 @@ function create_message_handler_loop(sock::AsyncStream) #returns immediately
815817
oid = deserialize(sock)
816818
#print("$(myid()) got $msg $oid\n")
817819
val = deserialize(sock)
818-
put(lookup_ref(oid), val)
820+
put!(lookup_ref(oid), val)
819821
elseif is(msg, :identify_socket)
820822
otherid = deserialize(sock)
821823
register_worker(Worker("", 0, sock, otherid))
@@ -1464,14 +1466,14 @@ function timedwait(testcb::Function, secs::Float64; pollint::Float64=0.1)
14641466
timercb(aw, status) = begin
14651467
try
14661468
if testcb()
1467-
put(done, :ok)
1469+
put!(done, :ok)
14681470
elseif (time() - start) > secs
1469-
put(done, :timed_out)
1471+
put!(done, :timed_out)
14701472
elseif status != 0
1471-
put(done, :error)
1473+
put!(done, :error)
14721474
end
14731475
catch e
1474-
put(done, :error)
1476+
put!(done, :error)
14751477
finally
14761478
isready(done) && stop_timer(aw)
14771479
end

‎doc/stdlib/base.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -4513,11 +4513,11 @@ Parallel Computing
45134513

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

4516-
.. function:: put(RemoteRef, value)
4516+
.. function:: put!(RemoteRef, value)
45174517

4518-
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``.
4518+
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.
45194519

4520-
.. function:: take(RemoteRef)
4520+
.. function:: take!(RemoteRef)
45214521

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

‎test/file.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,14 @@ rmdir(b_tmpdir)
6262
#######################################################################
6363
function test_file_poll(channel,timeout_s)
6464
rc = poll_file(file, iround(timeout_s/10), timeout_s)
65-
put(channel,rc)
65+
put!(channel,rc)
6666
end
6767

6868
function test_timeout(tval)
6969
tic()
7070
channel = RemoteRef()
7171
@async test_file_poll(channel,tval)
72-
tr = take(channel)
72+
tr = take!(channel)
7373
t_elapsed = toq()
7474
@test !tr
7575
@test tval <= t_elapsed
@@ -83,7 +83,7 @@ function test_touch(slval)
8383
f = open(file,"a")
8484
write(f,"Hello World\n")
8585
close(f)
86-
tr = take(channel)
86+
tr = take!(channel)
8787
@test tr
8888
end
8989

‎test/iterators.jl

+6-6
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,21 @@ macro test_buildvec(ex...)
1515
:(@test buildvec($(ex[1])) == $(ex[2]))
1616
end
1717

18-
@test_buildvec take(count(), 0) []
19-
@test_buildvec take(count(), 5) [0:4]
20-
@test_buildvec take(count(1,3), 5) [1:3:13]
21-
@test_buildvec take(count(zeros(2,2)), 3) [i * eye(2) for i=0:2]
18+
@test_buildvec take!(count(), 0) []
19+
@test_buildvec take!(count(), 5) [0:4]
20+
@test_buildvec take!(count(1,3), 5) [1:3:13]
21+
@test_buildvec take!(count(zeros(2,2)), 3) [i * eye(2) for i=0:2]
2222

2323
@test_buildvec drop(1:5, 5) []
2424
@test_buildvec drop(1:0, 0) []
2525
@test_buildvec drop(1:5, 2) [3:5]
2626

2727
@test_buildvec cycle(1:0) []
28-
@test_buildvec take(cycle(1:3), 8) [1:3,1:3,1:2]
28+
@test_buildvec take!(cycle(1:3), 8) [1:3,1:3,1:2]
2929

3030
@test_buildvec repeat('a', 0) []
3131
@test_buildvec repeat('a', 5) ['a' for i = 1:5]
32-
@test_buildvec take(repeat('a'), 5) ['a' for i = 1:5]
32+
@test_buildvec take!(repeat('a'), 5) ['a' for i = 1:5]
3333

3434
@test_buildvec chain() []
3535
@test_buildvec chain(1:0) []

‎test/netload/ltests.jl

+6-9
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ rr_sent = RemoteRef()
5151
end
5252
# println("process $(myid()) received $bread bytes")
5353
close(s)
54-
put(rr_rcd, true)
54+
put!(rr_rcd, true)
5555
end
5656
end)
5757

@@ -67,7 +67,7 @@ rr_sent = RemoteRef()
6767
end
6868
close(s)
6969
# println("process $(myid()) sent $bwritten bytes")
70-
put(rr_sent, true)
70+
put!(rr_sent, true)
7171
end)
7272

7373
wait(rr_rcd)
@@ -93,22 +93,19 @@ rr_client = RemoteRef()
9393
begin
9494
while (true)
9595
s=accept(server)
96-
@async begin xfer(s, xfer_exp); put(rr_server, true); take(rr_client); close(s); put(rr_server, true); end
96+
@async begin xfer(s, xfer_exp); put!(rr_server, true); take!(rr_client); close(s); put!(rr_server, true); end
9797
end
9898
end)
9999

100100

101101

102-
@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)
102+
@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)
103103

104-
take(rr_server)
105-
take(rr_client)
104+
take!(rr_server)
105+
take!(rr_client)
106106

107107
close(server)
108108

109109
println(" : OK")
110110

111111
@unix_only include("memtest.jl")
112-
113-
114-

‎test/parallel.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ rr1 = RemoteRef()
103103
rr2 = RemoteRef()
104104
rr3 = RemoteRef()
105105

106-
@async begin sleep(0.5); put(rr1, :ok) end
107-
@async begin sleep(1.0); put(rr2, :ok) end
108-
@async begin sleep(2.0); put(rr3, :ok) end
106+
@async begin sleep(0.5); put!(rr1, :ok) end
107+
@async begin sleep(1.0); put!(rr2, :ok) end
108+
@async begin sleep(2.0); put!(rr3, :ok) end
109109

110110
tic()
111111
timedwait(1.0) do

‎test/spawn.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ end
115115
yield()
116116
schedule(t, InterruptException(), error=true)
117117
yield()
118-
put(r,11)
118+
put!(r,11)
119119
yield()
120120

121121

0 commit comments

Comments
 (0)
Please sign in to comment.