[#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:04009] Re: Thread and File do not work together

From: "Michael Neumann" <neumann@...>
Date: 2000-07-14 12:22:24 UTC
List: ruby-talk #4009
From: "Yukihiro Matsumoto" <matz@netlab.co.jp>
> [...]
> Thread.start creates new thread and fork it, then readline meets EOF
> and raise error in the main thread.  When the main thread terminates
> whole process (including forked thread) be terminated too.
>
>   Thread.start {
>      print "ok\n"
>      print File::readlines("index.htm").to_s
>   }.join
>   readline
>
> will change the situation.
>
> matz.
>

Thanks, this works but is not what I want.
This would be exactly the same like using no threads, isn't it?
It seems to me that I cannot read from files inside a thread. If I do so,
the thread terminates.

Following example hangs, if I try to read from a file:

require "socket"
gs = TCPServer.open(1000)

while true
  ns = gs.accept
  print(ns, " is accepted\n")
  Thread.start do
    s = ns   # save to dynamic variable
    while s.gets
      s.write($_)

      f = File::open("ib_test.rb")
      print "before\n"
      f.gets                                                     # here the
thread terminates/hangs
      print "after\n"

    end
    print(s, " is gone\n")
    s.close
  end
end


---
Michael



In This Thread