ohm
ohm copied to clipboard
Update ohm.rb
Don't lazy initialize mutex, it's not thread safe.
If you intended to have one unique mutex per class (e.g. derived classes have a unique mutex) I believe something like this is required...
class Model
@mutex = Mutex.new
def self.inherited(derived)
derived.instance_variable_set(:@mutex, Mutex.new)
end
def self.mutex
@mutex
end
def self.synchronize(&block)
mutex.synchronize(&block)
end
end
class MyModel < Model
end
# These are both different:
pp Model.mutex
pp MyModel.mutex
I've tried the patch and I get errors when running the tests. Do you think it has to be an instance variable @mutex
or it can be a class variable @@mutex
?
Do you have CI? e.g. GitHub Actions.
You could experiment with the alternative code I gave you which makes it per-class rather than shared.
I tried it! But I get an error. You don't get errors?
I tested the code in isolation to check it behaved the same, but not running tests for this project. Can you set up CI?
Yes, I'll do it tomorrow as it's already late here. Thanks!
Bump :)