>From the code below, it appears that $! is thread safe.

Is it?

Thanks.

gegroet,
Erik V. - http://www.erikveen.dds.nl/

----------------------------------------------------------------

 # OUTPUT:
 # T=1 -> [1, :a, 1]
 # T=2 -> [2, :a, 2]
 # T=3 -> [3, :b, 2]
 # T=4 -> [4, :b, 1]

 Thread.abort_on_exception       = true

 dt      = lambda{t0=Time.now ; lambda{|*a| p [(Time.now-t0).to_i,
*a]}}[]

 class MyException < StandardError
   def initialize(n)
     @n  = n
   end

   def inspect
     @n.to_s
   end
 end

 (1..2).each do |m|
   Thread.new(m) do |n|
     begin
       sleep(n)                  # t1 -> sleep(1) ; t2 -> sleep(2)

       raise MyException.new(n)
     rescue
       dt[:a, $!]                # t1 -> T=1      ; t2 -> T=2

       sleep(5-2*n)              # t1 -> sleep(3) ; t2 -> sleep(1)

       dt[:b, $!]                # t1 -> T=4      ; t2 -> T=3
     end
   end
 end

 sleep 5

----------------------------------------------------------------