Roger Pack wrote:
...
> Also load up all your functions/everything 'single threaded' otherwise 
> some of the functions will be 'assigned' to the wrong thread (ugh), then 
> be unavailable (classes, modules, too).
> I.e. dynamically declared functions are dangerous.

In ruby, everything is dynamically defined. The closest you can get to 
static definitions is to require all your lib files before starting 
threads. Even so, it's not really static. It might be safer in some 
cases because require-ing a file is not atomic.(*) That's a corner case, 
though.

I don't think it's possible for things to be unavailable because they 
were loaded in the wrong thread, though. Got an example?

> Note also that sometimes if you are reading from TCPSockets the sockets 
> get confused and start reading from one another.

Really? I've never seen that, even with pretty heavy use of lots of 
threads and sockets.

----

(*) An example:

[~/tmp] cat a.rb

t = Thread.new do
   loop do
     sleep 0.1
     puts "a"
   end
end

sleep 0.5

require 'b'

[~/tmp] cat b.rb
t = Thread.new do
   loop do
     sleep 0.1
     puts "      b"
   end
end

sleep 1
t.kill

[~/tmp] ruby a.rb
a
a
a
a
a
       b
a
       b
a
       b
a
       b
a
       b
a
       b
a
       b
a
       b
a
       b
a


-- 
       vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407