ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: merch-redmine@jeremyevans.net
To: ruby-core@ruby-lang.org
Subject: [ruby-core:99911] [Ruby master Bug#17146] Queue operations are allowed after it is frozen
Date: Fri, 04 Sep 2020 01:52:14 +0000 (UTC)	[thread overview]
Message-ID: <redmine.journal-87442.20200904015213.772@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-17146.20200903225323.772@ruby-lang.org

Issue #17146 has been updated by jeremyevans0 (Jeremy Evans).


If a Queue cannot push/pop, it is useless.  A Queue doesn't have any operations on that would make sense if you cannot push/pop.  This makes it  different from most freezable objects, where the object is usable read-only in a frozen state.

In relation to Ractor/deep_freeze discussion, if deep_freeze is called on an object that contains a Queue (directly or transitively), and Queue#freeze makes the Queue unusable, it seems very dangerous.  It would be best if Queue was an shareable object whose operations worked across Ractors.  For example, assuming the object was sharable, a push of the object onto the Queue on Ractor A, while Ractor B, C, and D were waiting in Queue#pop, would result in only one of B, C, D popping the object. However, I don't know whether or not that is feasible.

I think the best solution for `Queue#freeze` is `Queue.send(:undef_method, :freeze)`.

----------------------------------------
Bug #17146: Queue operations are allowed after it is frozen
https://bugs.ruby-lang.org/issues/17146#change-87442

* Author: Eregon (Benoit Daloze)
* Status: Open
* Priority: Normal
* ruby -v: ruby 2.6.6p146 (2020-03-31 revision 67876) [x86_64-linux]
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN
----------------------------------------
```
[1] pry(main)> q = Queue.new
=> #<Thread::Queue:0x000056263683aee8>
[2] pry(main)> q.freeze
=> #<Thread::Queue:0x000056263683aee8>
[3] pry(main)> q << 1
=> #<Thread::Queue:0x000056263683aee8>
[4] pry(main)> q.pop
=> 1
[5] pry(main)> q.frozen?
=> true
```

Found by @ko1 in https://bugs.ruby-lang.org/issues/17100#note-28

I think it's a bug, since those are clear mutations.
I guess old Thread::Queue implemented in Ruby did not have this bug.



-- 
https://bugs.ruby-lang.org/

  parent reply	other threads:[~2020-09-04  1:52 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-03 22:53 [ruby-core:99903] [Ruby master Bug#17146] Queue operations are allowed after it is frozen eregontp
2020-09-04  0:58 ` [ruby-core:99908] " ko1
2020-09-04  1:52 ` merch-redmine [this message]
2020-09-04  3:56 ` [ruby-core:99913] " ko1
2020-09-13  9:25 ` [ruby-core:99999] " eregontp
2020-10-26 16:42 ` [ruby-core:100587] " ko1
2021-10-20 14:23 ` [ruby-core:105695] " Eregon (Benoit Daloze)
2021-10-20 14:44 ` [ruby-core:105698] " jeremyevans0 (Jeremy Evans)
2021-10-20 15:53 ` [ruby-core:105699] " Eregon (Benoit Daloze)
2021-10-20 15:56 ` [ruby-core:105700] " Eregon (Benoit Daloze)
2021-10-20 16:17 ` [ruby-core:105702] " jeremyevans0 (Jeremy Evans)
2021-10-20 17:58 ` [ruby-core:105704] " Eregon (Benoit Daloze)
2021-10-20 20:32 ` [ruby-core:105705] " ioquatix (Samuel Williams)
2023-09-14  5:37 ` [ruby-core:114739] " matz (Yukihiro Matsumoto) via ruby-core
2023-09-14 13:36 ` [ruby-core:114751] " mame (Yusuke Endoh) via ruby-core
2023-09-27  0:21 ` [ruby-core:114900] " jeremyevans0 (Jeremy Evans) via ruby-core

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.ruby-lang.org/en/community/mailing-lists/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=redmine.journal-87442.20200904015213.772@ruby-lang.org \
    --to=ruby-core@ruby-lang.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).