multithreading - Share variable through ruby processes -
i'm writing gem, have fork 2 processes starting 2 webrick servers. want start servers through class method base class, because there should 2 servers running, not multiple ones. during runtime, want call methods on 2 servers change variables.
my problem is, can't access instance variables of forks, through class method of base class. furthermore, can't use threads inside base class, because under hood i'm using library not thread safe. have fork each server it's own process.
i tried class variables, @@server. when try access variables through base class, it's nil. read sharing class variables among forks isn't possible in ruby, right?
so, there other way around this? thought of using singleton, i'm not sure if best idea.
when fork process child , parent processes's memory separated, cannot share variables between them directly. singleton class not work in case.
the solution ipc, ruby supports both pipes , sockets, 2 used forms of ipc, @ least on *nix. ruby supports distributed objects, if need more transparent interface.
what chose depends on job. if know want split processes on several computers @ point, go sockets or drb. if not go pipes.
Comments
Post a Comment