[#111712] [Ruby master Feature#19322] Support spawning "private" child processes — "kjtsanaktsidis (KJ Tsanaktsidis) via ruby-core" <ruby-core@...>
SXNzdWUgIzE5MzIyIGhhcyBiZWVuIHJlcG9ydGVkIGJ5IGtqdHNhbmFrdHNpZGlzIChLSiBUc2Fu
14 messages
2023/01/07
[ruby-core:112039] [Ruby master Misc#19376] (Please close) Ability to read ivars of non-frozen classes/modules across ractors is not thread-safe
From:
"luke-gru (Luke Gruber) via ruby-core" <ruby-core@...>
Date:
2023-01-25 16:41:01 UTC
List:
ruby-core #112039
Issue #19376 has been updated by luke-gru (Luke Gruber).
Tracker changed from Bug to Misc
Subject changed from Ability to read ivars of non-frozen classes/modules across ractors is not thread-safe to (Please close) Ability to read ivars of non-frozen classes/modules across ractors is not thread-safe
Backport deleted (2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN)
Nevermind this is actually safe, I ran into a separate segfault that this example was giving that's unrelated to that thread-safety issue. I'll file separate bug.
----------------------------------------
Misc #19376: (Please close) Ability to read ivars of non-frozen classes/modules across ractors is not thread-safe
https://bugs.ruby-lang.org/issues/19376#change-101472
* Author: luke-gru (Luke Gruber)
* Status: Open
* Priority: Normal
----------------------------------------
This segfaults:
```ruby
class C
class << self
attr_accessor :val
end
end
GO = false
rs = 100.times.map do
Ractor.new do
Thread.pass until GO
1000.times do
val = C.val
p val
end
end
end
ts = 100.times.map do |i|
Thread.new do
Thread.pass until GO
1000.times do
C.val = Object.new.freeze
end
end
end
GO = true
ts.each(&:join)
rs.each(&:take)
```
It looks like a silly example, but it can crash even if the main thread doesn't spawn any more threads. Getting/setting ivars on objects in parallel without VM lock isn't safe, so for non-frozen shareable objects (basically classes and modules), it's unsafe to access their instance variables even if the values are shareable.
--
https://bugs.ruby-lang.org/
______________________________________________
ruby-core mailing list -- [email protected]
To unsubscribe send an email to [email protected]
ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/