[#3986] Re: Principle of least effort -- another Ruby virtue. — Andrew Hunt <andy@...>

> Principle of Least Effort.

14 messages 2000/07/14

[#4043] What are you using Ruby for? — Dave Thomas <Dave@...>

16 messages 2000/07/16

[#4139] Facilitating Ruby self-propagation with the rig-it autopolymorph application. — Conrad Schneiker <schneik@...>

Hi,

11 messages 2000/07/20

[ruby-talk:04016] Re: Thread and File do not work together

From: Dave Thomas <Dave@...>
Date: 2000-07-14 14:07:52 UTC
List: ruby-talk #4016
"Michael Neumann" <neumann@s-direktnet.de> writes:

> It seems to me that I cannot read from files inside a thread. If I do so,
> the thread terminates.

Does the following code work for you (run it with the number of
threads to start as an argument)

     threads = []
     1.upto(ARGV[0].to_i) do |num|
       puts "In thread #{num}"
       thread = Thread.start do
         myNumber = num
         IO.foreach("/etc/fstab") do |line|
           puts "#{myNumber}: #{line}"
           Thread.pass
         end
       end
       threads << thread
       puts "Leaving thread #{num}"
     end

     threads.each { |t| t.join }

If so, then you may just have a simple bug in your code. Try setting

    Thread.abort_on_exception = true

and running your code.


Regards


Dave

In This Thread