Reputation: 15845
Does anyone know of an existing ruby implementation of a read/write lock - http://en.wikipedia.org/wiki/Readers-writer_lock?
Preferably this would be in a popular library or some other implementation that's been used by enough people that it's fairly bulletproof at this point.
Upvotes: 4
Views: 2138
Reputation: 7685
Within concurrent-ruby
gem you find Concurrent::ReadWriteLock
and Concurrent::ReentrantReadWriteLock
.
lock = Concurrent::ReadWriteLock.new
lock.with_read_lock { data.retrieve }
lock.with_write_lock { data.modify! }
Upvotes: 0
Reputation: 30445
The link in Jonas' blog is now broken, but I have built and tested another implementation, and anybody who wants to use it is welcome to:
https://github.com/alexdowad/showcase/blob/master/ruby-threads/read_write_lock.rb
Upvotes: 1