Shared Variable Among Ruby Processes
Posted
by Jesse J
on Stack Overflow
See other posts from Stack Overflow
or by Jesse J
Published on 2010-06-16T20:57:22Z
Indexed on
2010/06/16
21:22 UTC
Read the original article
Hit count: 299
I have a Ruby program that loads up two very large yaml files, so I can get some speed-up by taking advantage of the multiple cores by forking off some processes. I've tried looking, but I'm having trouble figuring how, or even if, I can share variables in different processes.
The following code is what I currently have:
@proteins = ""
@decoyProteins = ""
fork do
@proteins = YAML.load_file(database)
exit
end
fork do
@decoyProteins = YAML.load_file(database)
exit
end
p @proteins["LVDK"]
P
displays nil though because of the fork.
So is it possible to have the forked processes share the variables? And if so, how?
© Stack Overflow or respective owner