[#115244] [Ruby master Feature#19987] add sample method to Range — "horv77@... (Andras Horvath) via ruby-core" <ruby-core@...>
Issue #19987 has been reported by horv77@protonmail.com (Andras Horvath).
6 messages
2023/11/05
[#115247] [Ruby master Feature#19988] AI for inner code behavior analysis at runtime — "horv77@... (Andras Horvath) via ruby-core" <ruby-core@...>
Issue #19988 has been reported by horv77@protonmail.com (Andras Horvath).
3 messages
2023/11/05
[#115404] Ruby 3.2.2 - rbconfig.rb's MAKEFILE_CONFIG — Jay Mav via ruby-core <ruby-core@...>
Hello Ruby Dev Team,
4 messages
2023/11/17
[ruby-core:115387] [Ruby master Bug#8444] Regexp vars $~ and friends are not thread local
From:
"nobu (Nobuyoshi Nakada) via ruby-core" <ruby-core@...>
Date:
2023-11-14 04:49:23 UTC
List:
ruby-core #115387
Issue #8444 has been updated by nobu (Nobuyoshi Nakada).
Description updated
"Thread-local" in that sentence was wrong, and removed at commit:932dd9f10e684fa99b059054fbc934607d85b45a, but "method-local" is removed too.
----------------------------------------
Bug #8444: Regexp vars $~ and friends are not thread local
https://bugs.ruby-lang.org/issues/8444#change-105324
* Author: jamespharaoh (James Pharaoh)
* Status: Open
* Priority: Normal
* Assignee: ko1 (Koichi Sasada)
* ruby -v: trunk
----------------------------------------
In the docs for the Regexp special variables, `$~` and friends, it says "These global variables are thread-local and method-local variables". However the following gives an unexpected result:
```ruby
def get_proc
proc do |str|
str =~ /(.+)/
sleep 0.1
puts "got #{$1} from #{str}\n"
end
end
proc = get_proc
t1 = Thread.new { proc.call "abc" }
t2 = Thread.new { proc.call "def" }
t1.join
t2.join
```
This outputs the following:
```
got abc from abc
got abc from def
```
The expected result is of course:
```
got abc from abc
got def from def
```
Clearly the variables are being scoped to the `get_proc` method and are being shared by both threads. This runs contrary to the documentation and also to expectations.
This behaviour should either be changed, or the documentation updated to reflect the actual behaviour.
Interestingly, the following does work as expected:
```ruby
proc = proc do |str|
str =~ /(.+)/
sleep 0.1
puts "got #{$1} from #{str}\n"
end
t1 = Thread.new { proc.call "abc" }
t2 = Thread.new { proc.call "def" }
t1.join
t2.join
```
--
https://bugs.ruby-lang.org/
______________________________________________
ruby-core mailing list -- ruby-core@ml.ruby-lang.org
To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/