Probably the easiest way to make IPC in ruby is drb and use Queuewhich is in thread:
require 'thread'
queue = Queue.new
Note that when using drb, you want to have the following line at the top of your program:
Socket.do_not_reverse_lookup=true;
Without this, everything happens very slowly ( source ).
To solve the specific problem described in the question, you can create a class Pipethat essentially consists of only two objects Queue, one for incoming and one for outgoing. Read lock behavior Queuesimplifies the process of waiting for each other. Pipeshared between two processes through drb.
:
require 'drb'
Socket.do_not_reverse_lookup=true;
uri = "druby://localhost:2250"
pipe = Pipe.new
DRb.start_service uri, pipe
:
require 'drb'
Socket.do_not_reverse_lookup=true;
uri = "druby://localhost:2250"
DRb.start_service
pipe = DRbObject.new nil, uri
Pipe.