ruby-concurrency / ruby-concurrency/concurrent-ruby
Concurrent::Hash and Concurrent::Array are not fully threadsafe on CRuby
Offen
@eregon arbeitet bereits daran.
Seit 10.3.2023.
high-priority
- Vorherrschende Sprache
- Ruby
- Sterne
- 5.8k
- Forks
- 420
- Ø Merge
- 20 Std. 45 Min.
- Gemergte PRs (30 T.)
- 4
Beschreibung
Concurrent::Hash and Concurrent::Array are not fully threadsafe on CRuby.
This can be demonstrated for Array with:
require 'concurrent/array'
array = Concurrent::Array.new
array << 0
20.times.map do |i|
Thread.new { array.map!{|v| sleep 0.001; v + 1} }
end.each(&:join)
p array
This returns [1].
For Hash this code shows the issue:
require 'concurrent/hash'
hash = Concurrent::Hash.new
hash[:a] = 0
20.times.map do |i|
Thread.new { hash.transform_values!{|v| sleep 0.001; v + 1} }
end.each(&:join)
p hash
This returns {a: 1}.
In both cases we would expect to see 20 instead of 1.
* Ruby implementation: Ruby
* `concurrent-ruby` version: 1.1.9
* `concurrent-ruby-ext` installed: no
* `concurrent-ruby-edge` used: no
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Bewertung
Dieses Issue wurde noch nicht bewertet.