-
Notifications
You must be signed in to change notification settings - Fork 419
ReadWriteLock donated by @alexdowad #259
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
Conversation
@jdantonio, thank you very much for cleaning up my code! |
@alexdowad No clean up was necessary. Your code is awesome! All I had to do was integrate it into the project. Thank you very much for donating it! |
result = yield | ||
release_read_lock | ||
result | ||
end |
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.
better to wrap release_read_lock
in ensure
block, to prevent leaving it locked
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.
My next commit will have an ensure
block that releases the lock but is also sensitive to errors raised before the lock is acquired (such as when the maximum number of readers/writers is reached).
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.
right, it has to be:
def with_read_lock
acquire_read_lock
begin
yield
ensure
release_read_lock
end
end
not just ensure at the end, good catch
@alexdowad Thanks for the code! |
The complex conditions could be extracted to methods to improve readability. E.g. def readers(c = @count.value)
c & MAX_READERS
end
def waiting_writer?(c = @counter.value)
c >= WAITING_WRITER
end
# etc |
96b0196
to
c5e2e04
Compare
I believe this PR is ready to merge. It has nearly 100% code coverage, full yardoc, better exception handling, a few readability updates (methods for some of the bitwise operations used in conditionals), and the stress tests still pass with comparable performance. |
5a1aa83
to
3e1b83c
Compare
ReadWriteLock donated by @alexdowad
Merges
ReadWriteLock
donated by @alexdowad in #146.lib/concurrent/atomic
directoryexamples/benchmark_read_write_lock.rb
OptionsParser
To-do