11 ms·
Looks good. Id suggest making your `get` wait to acquire the lock until needed. eg instead of @lock.synchronize do entry = @store[key] return nil unl
by JamesSwift 1y ago
Looks good. Id suggest making your `get` wait to acquire the lock until needed. eg instead of
@lock.synchronize do
entry = @store[key]
return nil unless entry
...
you can do
entry = @store[key]
return nil unless entry
@lock.synchronize do
entry = @store[key]
And similarly for other codepaths
- chowells 1y agoDoes the memory model guarantee that double-check locking will be correct? I don't actually know for ruby.
- JamesSwift 1y agoI think it wouldnt even be a consideration on this since we arent initializing the store here only accessing the key. And theres already the check-then-set race condition in that scenario so I think it is doubly fine.
- hp_hovercraft84 1y agoGood call, but I think I would like to ensure it remains thread-safe as @store is a hash. Although I will consider something like this in a future update. Thanks!