From: eregontp@... Date: 2020-11-12T21:31:12+00:00 Subject: [ruby-core:100823] [Ruby master Feature#17322] Deprecate `Random::DEFAULT` and introduce `Random.default()` method to provide Ractor-supported default random generator Issue #17322 has been updated by Eregon (Benoit Daloze). In JRuby and in TruffleRuby, Random instances are thread-safe (i.e., they use synchronization internally). Also, `rand`, etc, use a per-Thread Random instance to avoid needless contention when calling `rand` in multiple threads concurrently. So, I agree we should deprecate Random::DEFAULT. I think `rand`, etc should use a thread-local Random instance (and thread-local implies Ractor-local, of course). That thread-local Random instance should probably not be exposed to the Ruby level, so that way there is never a need to synchronize access to it. So, I think we should deprecate Random::DEFAULT without replacement. Is there any case where it's useful? ---------------------------------------- Feature #17322: Deprecate `Random::DEFAULT` and introduce `Random.default()` method to provide Ractor-supported default random generator https://bugs.ruby-lang.org/issues/17322#change-88462 * Author: ko1 (Koichi Sasada) * Status: Open * Priority: Normal ---------------------------------------- `Random::DEFAULT` a default random generator used by `rand`, `srand`, `Array#shuffle` without a given random generator, and so on. Random generators are not thread-safe, so they are not ractor safe, and they are not shareable. So a program refer to `Random::DEFAULT` on non-main ractor, it causes an error. To provide per-ractor default random generator, this ticket propose the `Random.default()` method which returns per-ractor random generator. `Random::DEFAULT` is a result of `Random.default()` on main-ractor and it should be deprecated, or at least it should not be used on multi-ractor supporting apps and libraries. -- https://bugs.ruby-lang.org/ Unsubscribe: