[#101179] Spectre Mitigations — Amel <amel.smajic@...>
Hi there!
5 messages
2020/12/01
[#101694] Ruby 3.0.0 Released — "NARUSE, Yui" <naruse@...>
V2UgYXJlIHBsZWFzZWQgdG8gYW5ub3VuY2UgdGhlIHJlbGVhc2Ugb2YgUnVieSAzLjAuMC4gRnJv
4 messages
2020/12/25
[ruby-core:101376] [Ruby master Feature#17357] `Queue#pop` should have a block form for clsoed queues
From:
marcandre-ruby-core@...
Date:
2020-12-10 09:35:42 UTC
List:
ruby-core #101376
Issue #17357 has been updated by marcandre (Marc-Andre Lafortune).
Status changed from Feedback to Open
General use case: using `Queue` for objects that might be `nil`.
Why *I* opened this issue? I am writing a pure-Ruby backport of Ractor (using `Thread`). I am using `Queue` for messaging queues. `nil` can be value sent / received by Ractors (e.g. `Ractor.yield`).
So to be safe, I need to wrap/unwrap `nil` values.
My concern is same as with `timeout:` option: we have an "easy" way to do something that works 99%+ of the time, but is not 100% safe. Currently the only 100% way is difficult. People are lazy. We need to give easy 100% solution.
----------------------------------------
Feature #17357: `Queue#pop` should have a block form for clsoed queues
https://bugs.ruby-lang.org/issues/17357#change-89135
* Author: marcandre (Marc-Andre Lafortune)
* Status: Open
* Priority: Normal
----------------------------------------
It is currently difficult to reliably distinguish a `nil` value in a queue from the `nil` that is returned when a Queue is closed:
```ruby
n = 100_000
result = []
t2 = Thread.new { n.times { Thread.pass }} # to make things less predictable
n.times.count do
q = Queue.new
t = Thread.new { q.pop; result << q.closed? }
q << nil
q.close
t.join
end
puts result.count(true) # => some number usually > 9990 and < 10000
````
To be completely sure, one needs a Mutex or wrap/unwrap `nil` values.
`Queue#pop` should offer a surefire way to handle closed queues. I propose that an optional block be called in this case:
```ruby
q = Queue.new.close
q.pop # => nil
q.pop { :closed } # => :closed
````
Proposed PR: https://github.com/ruby/ruby/pull/3830
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>