-
Notifications
You must be signed in to change notification settings - Fork 417
Description
The docs for Concurrent::Set state (emphasis mine)
This version locks against the object itself for every method call, ensuring only one thread can be reading or writing at a time. This includes iteration methods like
#each.
However, on CRuby, the implementation of Concurrent::Set is just the built-in Set (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:
This version locks against the object itself for every method call, ensuring only one thread can be reading or writing at a time. This includes iteration methods like
#each.NOTE: On CRuby this is simply an alias for
Setand does not support concurrent modification during iteration. PreferConcurrent::Mapinstead.
* Ruby implementation: Ruby
* `concurrent-ruby` version: 1.1.8, but this applies to all versions afaict