rom-rb / rom-factory

Data generator with support for persistence backends
MIT License
83 stars 42 forks source link

Make registry fully thread safe #80

Closed mensfeld closed 1 year ago

mensfeld commented 1 year ago

Without this change potential incrementation can "go away" and can actually mismatch by 1 if run in multiple threads the same time. This can lead to super weird errors where counter is not as expected (been there, took me ages to debug).

ref: https://github.com/ruby-concurrency/concurrent-ruby/issues/970

granthusbands commented 1 year ago

Concurrent::Map already has the necessary machinery, so using a new mutex means you now have two separate locks for one piece of data. You should use something like:

registery.compute(key) { |v| v+1 }
flash-gordon commented 1 year ago

@granthusbands thanks for the heads up