TLOPO-Futex
tlopo-futex is a Ruby gem providing a simple interface for file-based locking. It enables mutual exclusion between processes to ensure safe access to shared resources.
Features
- File-based locking mechanism
lock
,release
, andsynchronize
methods for efficient, non-blocking resource handling- Lightweight and reliable
Installation
Add this line to your Gemfile:
gem 'tlopo-futex'
Then run:
bundle install
Or install directly with:
gem install tlopo-futex
Usage
Basic Lock and Unlock Example
require 'tlopo/futex'
# Initialize the lock with a path to a lock file
lock = Tlopo::Futex.new('/tmp/my_lock_file')
# Lock, execute critical code, then release
lock.lock
# Critical section code goes here
lock.release
Checking Lock Status
You can check if the lock is currently active:
if lock.locked?
puts "Resource is locked by another process"
else
lock.lock
# Critical section code
lock.release
end
Using synchronize
for Automatic Locking
The synchronize
method locks and releases automatically, ensuring that the lock is properly released even if an error occurs.
lock.synchronize do
# Critical section code that needs exclusive access
end
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/tlopo-ruby/tlopo-futex.
License
This gem is available under the MIT License.
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/tlopo-ruby/tlopo-futex. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.
License
The gem is available as open source under the terms of the MIT License.
Code of Conduct
Everyone interacting in the Tlopo::Futex project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.