# # thread.rb - thread support classes # $Date$ # by Yukihiro Matsumoto # # Copyright (C) 2001 Yukihiro Matsumoto # Copyright (C) 2000 Network Applied Communication Laboratory, Inc. # Copyright (C) 2000 Information-technology Promotion Agency, Japan # unless defined? Thread fail "Thread not available for this ruby interpreter" end unless defined? ThreadError class ThreadError= @max @queue_wait.push Thread.current Thread.stop Thread.critical = true end super end alias << push def pop(*args) retval = super Thread.critical = true if @que.length < @max begin t = @queue_wait.shift t.wakeup if t rescue ThreadError retry ensure Thread.critical = false end begin t.run if t rescue ThreadError end end retval end def num_waiting @waiting.size + @queue_wait.size end end