Skip to content

[documentation] Concurrent::Set documentation is ambiguous, possibly misleading. #900

@grncdr

Description

@grncdr

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 Set and does not support concurrent modification during iteration. Prefer Concurrent::Map instead.

* Ruby implementation:             Ruby
* `concurrent-ruby` version:       1.1.8, but this applies to all versions afaict

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA bug in the library or documentation.high-priorityShould be done ASAP.looking-for-contributorWe are looking for a contributor to help with this issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions