From 80361a7712212fcc60c2ea6625f77103d0d9fce3 Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Tue, 16 Jul 2019 16:18:50 -0400 Subject: [PATCH] fix #32575, channel trying to switch to task on another thread (#32584) --- base/channels.jl | 4 ++-- test/threads_exec.jl | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/base/channels.jl b/base/channels.jl index 1cb6b5386f960..3653ec9c1a2b4 100644 --- a/base/channels.jl +++ b/base/channels.jl @@ -304,8 +304,8 @@ function put_unbuffered(c::Channel, v) finally unlock(c) end - # unfair version of: schedule(taker, v); yield() - yield(taker, v) # immediately give taker a chance to run, but don't block the current task + schedule(taker, v) + yield() # immediately give taker a chance to run, but don't block the current task return v end diff --git a/test/threads_exec.jl b/test/threads_exec.jl index a2e20dee695cf..05e060188eb93 100644 --- a/test/threads_exec.jl +++ b/test/threads_exec.jl @@ -665,3 +665,12 @@ let timeout = 300 # this test should take about 1-10 seconds end close(t) # stop the watchdog end + +# issue #32575 +let ch = Channel{Char}(0), t + t = Task(()->for v in "hello" put!(ch, v) end) + t.sticky = false + bind(ch, t) + schedule(t) + @test String(collect(ch)) == "hello" +end