-
Notifications
You must be signed in to change notification settings - Fork 419
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix ReentrantReadWriteLock
implementation when Mutex is per-fiber.
#983
Fix ReentrantReadWriteLock
implementation when Mutex is per-fiber.
#983
Conversation
7e6667c
to
21cea96
Compare
This PR also enables the tests under JRuby. |
Thread.current.local_variable...
for implementing thread locals.ReentrantReadWriteLock
implementation when Mutex is per-fiber.
Unfortunately I think we cannot just do that, and this is the reason that
Maybe the first point can be addressed with some Some pointers I could find about
There should definitely be better docs on |
Something interesting is I think we should probably create a FiberLocalVar, based on |
The rest of the PR looks good from a quick look. To give an example issue with the current PR: each |
That makes sense. I don’t think there is any way in Ruby to delete a thread local or fiber local variable |
Indeed, there is no such thing as Aside: I wonder if this is partly why I didn't mind the |
One way to deal with this would be to assume assigning nil deletes the value - i.e. nil is indistinguishable from unset. This seems like a problem we should solve in Ruby and avoid hacking around here (even if we need a short term fix). |
3efea70
to
3b50565
Compare
I've reverted back to the shared array implementation, and reworked it into Generally, it seems okay. I'm a little concerned about the A better solution might be to use a linked list for the |
7d83f9f
to
b001be7
Compare
@eregon I've done another pass over this, squashed all the commits, etc. Let me know if you want any further changes made. |
@ioquatix Could you rebase? (feel free to squash your changes to make the rebase easier) |
…cope. # Conflicts: # lib/concurrent-ruby/concurrent/atomic/reentrant_read_write_lock.rb # spec/concurrent/atomic/reentrant_read_write_lock_spec.rb
8586727
to
b1f4fee
Compare
Okay, rebase done. |
6f76667
to
4959d76
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see any specs for FiberLocalVar, this is necessary as we introduce a new public class.
87ad3a8
to
1db8e40
Compare
1db8e40
to
9c09274
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added specs for FiberLocalVar.
Should be good to go now, just waiting CI.
Thank you for the PR!
end | ||
|
||
def locals! | ||
thread = Thread.current | ||
locals = thread.thread_variable_get(@name) | ||
locals = thread.thread_variable_get(:concurrent_thread_locals) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change means that multiple instances of the class will clobber each other.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes but since we only need 1 instance we support just that and not more
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, fair enough.
Ruby 3.0+ is per-fiber Mutex. Currently, it's possible to get errors when using
ReentrantReadWriteLock
on different fibers. Let's fix that.Fixes #962