Issue #7429 has been updated by matz (Yukihiro Matsumoto).


@headius I am afraid it's not going to 2.0, for some reasons:

* it's too late to add new classes to 2.0
* and it will take more time to prepare parallel collection implementation for other Ruby (in this case mainly CRuby).
* the future CRuby will lean toward non threading way, e.g, Actors.

Matz.


----------------------------------------
Feature #7429: Provide options for core collections to customize behavior
https://bugs.ruby-lang.org/issues/7429#change-33879

Author: headius (Charles Nutter)
Status: Rejected
Priority: Normal
Assignee: 
Category: 
Target version: 2.0.0


Many folks know that Matz is a fan of having a few classes that handle a wide range of behavior. For this reason, I think we're unlikely to get a set of parallelism-safe collections added to Ruby. I propose an alternative that would allow parallel-executing implementations to offer concurrency-friendly versions without impact to any code.

I would like to see a way to pass in an options hash to the .new construction of at least Hash and Array. For example:

# Create a hash that is concurrenct-safe, resizes when density is > 3 keys per bucket,
# and sets initial bucket count to 60
hsh = Hash.new(concurrent: true, density: 3, size: 60)

Similar for Array:

ary = Array.new(concurrent: true, size: 100)

Options like density and size map directly to current implementation details of Hash and Array that are sometimes not accessible (you can't change the load factor for Hash, for example). Options like concurrent could be noops on MRI but would allow other implementations to provide safe versions of the collections behind the scenes.

I know it may be too late for 2.0.0, but we implementers of parallel-executing Rubies feel the pain of thread-unsafe core structures every day. I think the ability to get thread-safe collections in Ruby core would go a long way toward dispelling the myth that Ruby is bad for concurrent application programming.


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