diff --git a/src/cpp/channel.cpp b/src/cpp/channel.cpp index 7dd458f..5314e18 100644 --- a/src/cpp/channel.cpp +++ b/src/cpp/channel.cpp @@ -43,9 +43,8 @@ bool Channel::push(const sol::variadic_args& args) { } RETHROW_WITH_PREFIX("effil.channel:push"); } - if (ctx_->channel_.empty()) - ctx_->cv_.notify_one(); ctx_->channel_.emplace(array); + ctx_->cv_.notify_one(); return true; } diff --git a/tests/lua/channel-stress.lua b/tests/lua/channel-stress.lua index 0770bb0..1dfffcc 100644 --- a/tests/lua/channel-stress.lua +++ b/tests/lua/channel-stress.lua @@ -1,5 +1,7 @@ require "bootstrap-tests" +local effil = require "effil" + test.channel_stress.tear_down = default_tear_down test.channel_stress.with_multiple_threads = function () @@ -90,3 +92,31 @@ test.channel_stress.retun_tables = function () thr:wait() end end + +-- regress for multiple wait on channel +test.channel_stress.regress_for_multiple_waiters = function () + for i = 1, 20 do + local chan = effil.channel() + local function receiver() + return chan:pop(5) ~= nil + end + + local threads = {} + for i = 1, 10 do + table.insert(threads, effil.thread(receiver)()) + end + + effil.sleep(0.1) + for i = 1, 100 do + chan:push(1) + end + + for _, thr in ipairs(threads) do + local ret = thr:get() + test.is_true(ret) + if not ret then + return + end + end + end +end