Hello all.
Patrick has been doing some excellent work on the “process_shared” gem,
which provides for cross process mutexes and shared memory, inspired by
Python’s multiprocessing library:
ex:
require ‘process_shared’
mutex = ProcessShared::Mutex.new
mem = ProcessShared::SharedMemory.new(:int)
mem.put_int(0, 0)
10.times {
fork do
puts “in process 1 (#{Process.pid})”
10.times do
sleep 0.01
mutex.synchronize do
value = mem.get_int(0)
sleep rand*0.1
puts “process 1 (#{Process.pid}) incrementing”
mem.put_int(0, value + 1)
end
end
end
}
Process.waitall
p mem.get_int(0) # always outputs 100
more advanced examples can be found in the specs:
It’s not quite “polished” but seems to work well for its use cases. It
has support for shared native primitives as well as “shared strings” to
use for marshalling more complex objects.
Thought I’d let people know of its existence. I’d also like to ask if
there are any other “features” that people would wish to see added to
the library (feel free to test it out, see how you like it). Anything
come to mind that would be useful?
Thanks!
-roger-