inter-process synchronization primitives using shared memory
C Ruby
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.


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.

- 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

require 'shlock'
f ="/test-mutex")
puts("locked the mutex once, grabbing lock again to spin-wait; go run process2.rb once locked up...\n")
puts("got the lock, exiting\n")

require 'shlock'
f ="/text-mutex")
puts "alive, unlocking"
puts "done, exiting"

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?