[#84867] [Ruby trunk Bug#14357] thread_safe tests suite segfaults — v.ondruch@...

Issue #14357 has been reported by vo.x (Vit Ondruch).

11 messages 2018/01/15

[#84980] [Ruby trunk Feature#13618][Assigned] [PATCH] auto fiber schedule for rb_wait_for_single_fd and rb_waitpid — hsbt@...

Issue #13618 has been updated by hsbt (Hiroshi SHIBATA).

10 messages 2018/01/23
[#85012] Re: [Ruby trunk Feature#13618][Assigned] [PATCH] auto fiber schedule for rb_wait_for_single_fd and rb_waitpid — Eric Wong <normalperson@...> 2018/01/23

hsbt@ruby-lang.org wrote:

[ruby-core:84576] [Ruby trunk Feature#9145] Queue#pop(true) return nil if empty instead of raising ThreadError

From: uwe@...
Date: 2018-01-01 19:41:23 UTC
List: ruby-core #84576
Issue #9145 has been updated by uwe@kubosch.no (Uwe Kubosch).


How about a block form where the block is called with the popped element?  The method would return false if called with non_block set to true if the queue is empty.

q = Queue.new
q << 1
q << 2
q << 3

while q.pop(true){|x| p x}


----------------------------------------
Feature #9145: Queue#pop(true) return nil if empty instead of raising ThreadError
https://bugs.ruby-lang.org/issues/9145#change-69116

* Author: jsc (Justin Collins)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
I propose the non-blocking form of Queue#pop behave like Array#pop and return nil when empty.

Current behavior is to raise a ThreadError, with a message indicating the queue is empty.

For example:

q = Queue.new
begin
  loop do
    next_item = q.pop(true)
  end
rescue ThreadError
  # queue is empty...or maybe something bad happened
end

Instead, this could be

q = Queue.new
while next_item = q.pop(true)
end

Alternatively, raise an exception that is a subclass of ThreadError with a more specific name, such as "QueueEmpty". This would be a small improvement while remaining compatible with existing code.



-- 
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>

In This Thread

Prev Next