Closed grncdr closed 3 years ago
Hi @grncdr, thanks for the report. It would be better to fix the implementation on CRuby though. It should also lock during the iteration since that is the behaviour of Concurrent::Set on JRuby and TruffleRuby. Could you contribute the fix please?
The docs for
Concurrent::Set
state (emphasis mine)However, on CRuby, the implementation of
Concurrent::Set
is just the built-inSet
(ref).Clearly, the built-in set does not perform any locking around method calls. This caused a few bugs for me when I used
Concurrent::Set
it for sharing state between threads. I had one thread iterating the set with#each
and other threads adding/deleting items from the set. This failed, since CRuby Set doesn't support mutating a set during iteration.Would a PR updating the docs to call this out explicitly be welcome? I would propose something like: