From: Konstantin Knizhnik Date: 2003-04-09T02:31:02+09:00 Subject: Creating thread safe classes for Ruby Hello, I want make my class correctly executed in multithreaded environment. That is why I am using mutex class to synchronize access to the object: require "thread" class Foo def initialize() @mutex = Mutex.new end def someCriticalMethod() @mutex.synchronize { ... do something } end end But if I then invoke this method outside any thread I will get the following error: C:/ruby-180/lib/ruby/1.8/thread.rb:94:in `stop': stopping only thread (ThreadError) note: use sleep to stop forever from C:/ruby-180/lib/ruby/1.8/thread.rb:94:in `lock' from C:/ruby-180/lib/ruby/1.8/thread.rb:127:in `synchronize' ... Is there some correct way in Ruby to write thread safe code which will be also executed outside thread context? -- Best regards, Konstantin mailto:knizhnik@garret.ru