Permalink
Browse files

fix produce() before consume(). closes #6010

better than an improved error message, make it work :)
  • Loading branch information...
1 parent 517039e commit d2d257b687d7f5498328be661858d9375cfe96b3 @JeffBezanson JeffBezanson committed Mar 2, 2014
Showing with 23 additions and 11 deletions.
  1. +15 −11 base/task.jl
  2. +8 −0 test/spawn.jl
View
@@ -93,14 +93,20 @@ function produce(v)
#t = shift!(q.waitq)
#empty = isempty(q.waitq)
ct = current_task()
- q = ct.consumers
- if isa(q,Condition)
- t = shift!(q.waitq)
- empty = isempty(q.waitq)
- else
- t = q
- ct.consumers = nothing
- empty = true
+ local empty, t, q
+ while true
+ q = ct.consumers
+ if isa(q,Task)
+ t = q
+ ct.consumers = nothing
+ empty = true
+ break
+ elseif isa(q,Condition) && !isempty(q.waitq)
+ t = shift!(q.waitq)
+ empty = isempty(q.waitq)
+ break
+ end
+ wait()
end
t.state = :runnable
@@ -144,9 +150,7 @@ function consume(P::Task, values...)
if P.consumers === nothing || (isa(P.consumers,Condition)&&isempty(P.consumers.waitq))
P.consumers = ct
else
- if P.consumers === nothing
- P.consumers = Condition()
- elseif isa(P.consumers, Task)
+ if isa(P.consumers, Task)
t = P.consumers
P.consumers = Condition()
push!(P.consumers.waitq, t)
View
@@ -126,3 +126,11 @@ exename=joinpath(JULIA_HOME,(ccall(:jl_is_debugbuild,Cint,())==0?"julia-basic":"
# issue #5904
@test run(ignorestatus(`false`) |> `true`) === nothing
+
+
+# issue #6010
+# TODO: should create separate set of task tests
+ducer = @async for i=1:100; produce(i); end
+yield()
+@test consume(ducer) == 1
+@test consume(ducer) == 2

0 comments on commit d2d257b

Please sign in to comment.