concurrent-ruby
concurrent-ruby copied to clipboard
concurrent-ruby-edge Channel.select consumes full(single core) cpu
* `concurrent-ruby` version: 1.1.7
* `concurrent-ruby-edge` used: yes
I am running this simple code and I see that select
is not blocking on the channels
and instead always looping
which consumes full(single core) CPU.
require 'concurrent-edge'
Channel = Concurrent::Channel
string1 = Channel.new
string2 = Channel.new
loop do
Channel.select do |s|
s.take(string1) {
puts "string1"
}
s.take(string2) {
puts "string2"
}
end
end
It is Ruby, not go, so it is not possible to push from another thread to the current one, like it is implemented in go's select
.
As the result you can only pull, which this select
is actually doing (and consuming 100% CPU).
Adding s.default { sleep 0.001 }
will solve it.