Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7545285
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T08:53:17+00:00 2026-05-30T08:53:17+00:00

Learning to use Ruby Threads for transportability of code between different OS platforms. The

  • 0

Learning to use Ruby Threads for transportability of code between different OS platforms.

The problem is the console is frozen until non_join1 completes which also prevents non_join2 from being started. non_join1 waits at the join command until the threads complete.

The software requires multiple routines running independently. The primary program is a standalone that runs in realtime collecting data. The data collected is written to files. Different programs, using Threads, process the data in parallel. The start/stop and status is controlled from a main console.

What is the best ruby method to launch the separate programs needed to analyze the data files and get status back from the threads?

thanks,
pb

# This is the console that starts up the multiple threads.
#!/usr/bin/ruby

loop do
puts " input a command"
command = gets.chop!
control = case command
    when "1" : "1"
    when "2" : "2"
    end
if control == "1" then 
puts `date`+ "routine 1"
puts `./non_join1.rb`
puts `date` 
end

if control == "2" then 
puts `date` + "routine 2"
`./non_join2.rb`    
end

end


#!/usr/bin/ruby
# Example of worker program 1 used to process data files
#file non_join1.rb
x = Thread.new { sleep 0.1; print "xxxxxxxxx"; print "yyyyyyyyyyy"; print "zzzzzzzzzz" }  
a = Thread.new { print "aaaaaaaaa"; print "bbbbbbbbbb"; sleep 0.1; print "cccccccc" } 
puts " "
(1..10).each {|i| puts i.to_s+" done #{i}"}
x.join
a.join
sleep(30)

#!/usr/bin/ruby
# Example of worker program 2 used to  process data files
#file non_join2.rb
x = Thread.new { sleep 0.1; print "xxxxxxxxx"; print "yyyyyyyyyyy"; print "zzzzzzzzzz" }  
a = Thread.new { print "aaaaaaaaa"; print "bbbbbbbbbb"; sleep 0.1; print "cccccccc" } 
x.join
a.join



$ ./call_ruby.rb 
 input a command
 1
 Sat Feb 18 10:36:43 PST 2012
 routine 1
 aaaaaaaaabbbbbbbbbb 
 1 done 1
 2 done 2
 3 done 3
 4 done 4
 5 done 5
 6 done 6
 7 done 7
 8 done 8
 9 done 9
 10 done 10
 xxxxxxxxxyyyyyyyyyyyzzzzzzzzzzcccccccc
 Sat Feb 18 10:37:13 PST 2012
 input a command
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T08:53:18+00:00Added an answer on May 30, 2026 at 8:53 am

    Instead of executing with “ try this forking (creating a new process), using for example this function:

    class Execute
      def self.run(command)
        pid = fork do
          Kernel.exec(command)
        end
        return pid
      end  
    end
    

    Your code will look like

    loop do
      puts " input a command"
      command = gets.chop!
      control = case command
        when "1" : "1"
        when "2" : "2"
      end
      if control == "1" then 
        puts `date`+ "routine 1"
        Execute.run("./non_join1.rb")
        puts `date` 
      end
    
      if control == "2" then 
        puts `date` + "routine 2"
        Execute.run("./non_join2.rb")
      end
    
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I recently started learning ruby, and I understood that you coud use code blocks
I installed Netbeans IDE 6.8 today to use it while learning Ruby. Here the
I am interested in learning python and ruby, but I use Windows 7. Most
I have been use the rails console for testing and learning purposes and when
I just started learning Ruby coming from Java. In Java you would use packages
I'm learning Selenium now. I'm going to use it in the Ruby on Rails
I just started learning Ruby, and for my sandbox I use latest Rubygems version,
I have been learning to use a slideshow code I saw on a website
I am just learning Ruby and I don't quite understand the difference between several
I am learning to use LabVIEW as part of my honours project, and was

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.