From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: poffice@blade.nagaokaut.ac.jp Delivered-To: poffice@blade.nagaokaut.ac.jp Received: from kankan.nagaokaut.ac.jp (kankan.nagaokaut.ac.jp [133.44.2.24]) by blade.nagaokaut.ac.jp (Postfix) with ESMTP id 686FE19E002D for ; Sat, 19 Dec 2015 22:05:24 +0900 (JST) Received: from voscc.nagaokaut.ac.jp (voscc.nagaokaut.ac.jp [133.44.1.100]) by kankan.nagaokaut.ac.jp (Postfix) with ESMTP id 58276B5D834 for ; Sat, 19 Dec 2015 22:37:34 +0900 (JST) Received: from neon.ruby-lang.org (neon.ruby-lang.org [221.186.184.75]) by voscc.nagaokaut.ac.jp (Postfix) with ESMTP id E8E0818CC7B8 for ; Sat, 19 Dec 2015 22:37:34 +0900 (JST) Received: from [221.186.184.76] (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 1E9B01204D2; Sat, 19 Dec 2015 22:37:33 +0900 (JST) X-Original-To: ruby-core@ruby-lang.org Delivered-To: ruby-core@ruby-lang.org Received: from o2.heroku.sendgrid.net (o2.heroku.sendgrid.net [67.228.50.55]) by neon.ruby-lang.org (Postfix) with ESMTPS id C756F12048D for ; Sat, 19 Dec 2015 22:37:29 +0900 (JST) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sendgrid.me; h=from:to:references:subject:mime-version:content-type:content-transfer-encoding:list-id; s=smtpapi; bh=LgHmFdUSlPQdr5Ha0+Q/uXudDS0=; b=WZ2YqldgZAsq1t1Yrk 7UIb++K7r6CsfEg9bxWXIFv3sRV5LhPIlKw6g3M3I98tKK14zZcM9C6ffrlz99OC 1xv8lGo7DQQECj/r3Hs9Gb7QKsqMb+Rw5MEwJVWnkToi5JJwAsCB/HLRBRwlboM/ H/ubTkrxYRKN4m/y29Od6ABw0= Received: by filter0536p1mdw1.sendgrid.net with SMTP id filter0536p1mdw1.357.56755D933D 2015-12-19 13:37:23.606546421 +0000 UTC Received: from herokuapp.com (ec2-54-146-198-157.compute-1.amazonaws.com [54.146.198.157]) by ismtpd0002p1iad1.sendgrid.net (SG) with ESMTP id 0Ow2B92QQVaQC8368wxBiA Sat, 19 Dec 2015 13:37:23.624 +0000 (UTC) Date: Sat, 19 Dec 2015 13:37:23 +0000 From: email@pitr.ch To: ruby-core@ruby-lang.org Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Redmine-MailingListIntegration-Message-Ids: 46975 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 11822 X-Redmine-Issue-Author: headius X-Redmine-Issue-Assignee: ko1 X-Redmine-Sender: pitr.ch X-Mailer: Redmine X-Redmine-Host: bugs.ruby-lang.org X-Redmine-Site: Ruby Issue Tracking System X-Auto-Response-Suppress: All Auto-Submitted: auto-generated X-SG-EID: ync6xU2WACa70kv/Ymy4QrNMhiuLXJG8OTL2vJD1yS61zoq4dWGpuvmsOncNT0TKVHR5ap6jqaiq27 5NG/ZvQ5x8fzxixhCOj4gwqxAcQfvpGhdKyig60C4XYY75aqan7lafrGLGYxYqafowywxmS9Gt2rO/ n5pOYqQXljX6jfLJ3XwJFtUa+FRwveFf24gW X-SendGrid-Contentd-ID: {"test_id":"1450532246"} X-ML-Name: ruby-core X-Mail-Count: 72380 Subject: [ruby-core:72380] [Ruby trunk - Bug #11822] Semantics of Queue#pop after close are wrong X-BeenThere: ruby-core@ruby-lang.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: Ruby developers List-Id: Ruby developers List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: ruby-core-bounces@ruby-lang.org Sender: "ruby-core" Issue #11822 has been updated by Petr Chalupa. Thank you for explanation. So nil can mean a normal nil pushed to the queue or closed queue, that might be error prone. As Charles mentioned there are many possible behaviors users might want when queue is closed. I would suggest to make this configurable on queue initialization. ~~~ ruby Queue.new on_close: nil # pops nil Queue.new on_close: :poison_pill # pops symbol :poison_pill CLOSED = Object.new Queue.new on_close: CLOSED # pops CLOSED Queue.new on_close: ClosedQueueError # raises exception of supplied class ~~~ Raising exception seems unnecessary to me, since close is normal feature of the queue not an exceptional state (this is subjective though so including in the example too). ---------------------------------------- Bug #11822: Semantics of Queue#pop after close are wrong https://bugs.ruby-lang.org/issues/11822#change-55670 * Author: Charles Nutter * Status: Open * Priority: Normal * Assignee: Koichi Sasada * ruby -v: * Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN ---------------------------------------- Current test/ruby/thread/test_queue.rb test_close has the following assertion that seems wrong to me: ```ruby def test_close [->{Queue.new}, ->{SizedQueue.new 3}].each do |qcreate| q = qcreate.call assert_equal false, q.closed? q << :something assert_equal q, q.close assert q.closed? assert_raise_with_message(ClosedQueueError, /closed/){q << :nothing} assert_equal q.pop, :something # <<< THIS ONE assert_nil q.pop assert_nil q.pop # non-blocking assert_raise_with_message(ThreadError, /queue empty/){q.pop(non_block=true)} end end ``` Once a queue is closed, I don't think it should ever return a result anymore. The queue should be cleared and pop should always return nil. In r52691, ko1 states that "deq'ing on closed queue returns nil, always." This test does not match that behavior. -- https://bugs.ruby-lang.org/