Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
|Failed to load latest commit information.|
What is shlock ? =============== shlock is a library that provides synchronization primitives that use shared memory. Currently, mutexes (Shlock::Putex) and rwlocks (Shlock::Prwlock) are implemented. Why ? ===== If want to synchronize two ruby processes without using those painful file locks, you can use this. TODO ==== - It is probably not safe to use these pthread exposed APIs in this way. I should probably reimplement the low-level locking primitives in C using atomic.h and futexes. - Add documentation about Shlock::Prwlock Sample Usage of Shlock::Putex ============================= process1.rb: require 'shlock' f = Shlock::Putex.new("/test-mutex") f.lock puts("locked the mutex once, grabbing lock again to spin-wait; go run process2.rb once locked up...\n") f.lock puts("got the lock, exiting\n") process2.rb: require 'shlock' f = Shlock::Putex.new("/text-mutex") puts "alive, unlocking" f.unlock puts "done, exiting" f.destroy in your terminal: % ruby process1.rb when it tells you to run process2.rb, in another terminal enter: % ruby process2.rb you should see process2 unlock process1 and allow it to exit. What's next ? ============= Maybe some more process-to-process synchronization primitives?