ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: eregontp@gmail.com
To: ruby-core@ruby-lang.org
Subject: [ruby-core:84851] [Ruby trunk Bug#14353] $SAFE should stay at least thread-local for compatibility
Date: Sat, 13 Jan 2018 19:33:42 +0000 (UTC)	[thread overview]
Message-ID: <redmine.journal-69563.20180113193341.8faa3bc2018b27a8@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-14353.20180113193325@ruby-lang.org

Issue #14353 has been updated by Eregon (Benoit Daloze).

Assignee set to ko1 (Koichi Sasada)

----------------------------------------
Bug #14353: $SAFE should stay at least thread-local for compatibility
https://bugs.ruby-lang.org/issues/14353#change-69563

* Author: Eregon (Benoit Daloze)
* Status: Open
* Priority: Normal
* Assignee: ko1 (Koichi Sasada)
* Target version: 
* ruby -v: 
* Backport: 2.3: UNKNOWN, 2.4: UNKNOWN, 2.5: UNKNOWN
----------------------------------------
In #14250 $SAFE changed from a frame+thread-local variable to a process-wide global variable.

This feels wrong and breaks the most common usage of $SAFE in tests:

~~~ ruby
Thread.new {
  $SAFE = 1
  sth that should be checked to work under $SAFE==1
}.join
~~~

It is very clear this is incompatible given how many files (33!) had to be changed in r61510.
And it has wide ranging confusing side-effects, one example: https://travis-ci.org/ruby/spec/jobs/328524568

I agree frame-local is too much for $SAFE.

But removing thread-local seems to only introduce large incompatibilities.

It also makes it impossible to use it in a thread-safe way.
The common pattern (not necessarily for $SAFE, more often for $VERBOSE):

~~~ ruby
begin
  old = $SAFE
  $SAFE = 1
  something under SAFE==1
ensure
  $SAFE = old
end
~~~

is unsafe if two threads run it concurrently (The last thread executing `$SAFE = old` might restore to 1 even though it should be 0).

(Actually I believe most built-in variables (e.g. $VERBOSE) should be thread-local and not process-wide due to this)

Since $SAFE is being deprecated and removed, I don't see any reason to make it more incompatible than needed.

@ko1 Can we switch it back to thread-local for compatibility, avoiding headaches and keeping it usable with multiple threads?



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

  parent reply	other threads:[~2018-01-13 19:33 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <redmine.issue-14353.20180113193325@ruby-lang.org>
2018-01-13 19:33 ` [ruby-core:84850] [Ruby trunk Bug#14353] $SAFE should stay at least thread-local for compatibility eregontp
2018-01-13 19:33 ` eregontp [this message]
2018-01-13 22:24 ` [ruby-core:84852] " shevegen
2018-01-16  3:14 ` [ruby-core:84886] " ko1
2018-01-16 17:14 ` [ruby-core:84892] " eregontp
2019-01-23  9:25 ` [ruby-core:91222] " v.ondruch
2019-02-07  5:23 ` [ruby-core:91447] " matz
2019-10-17 23:35 ` [ruby-core:95406] [Ruby master " merch-redmine

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-69563.20180113193341.8faa3bc2018b27a8@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).