hi...

Following prorgam, executes in a loop 10 non-ending threads and 10 threads
which should kill
the non-ending after one second.
But this do not work.
If I comment the "sleep 1" out, then all threads are killed.
Why doesn't work this program correctly?


Michael


--------------------------------------
require 'thread'

m = Mutex.new
$active_threads = 0

for i in (1..10)
   y = Thread.start do
      begin
         m.synchronize { print "Active Threads: ", $active_threads +=
1,"\n" }
         sleep
      ensure
         m.synchronize { print "Active Threads: ", $active_threads -=
1,"\n" }
      end
   end

   Thread.start do
      sleep 1
      if y.alive? then
         y.exit
      end
   end
end

# wait until all threads are killed
while $active_threads > 0 do end
--------------------------------------