From: Kirk Haines Date: 2005-04-10T05:14:40+09:00 Subject: Re: My threading concern. Aaron Rustad wrote: > When two theads enter a method that can change a value of an instance > variable, does the possiblity exist that one thread's changes will > clobber the other's? > > The reason stems from the ApplicationController of Rails, when a > request is received, the request is handled by a method that has access > to instance variables (session, request, params). Coming from the > Java/Struts world, this is a concern, and methods should not access > instance variables. > > Is there a different model of theading in Ruby, or, would I be missing > something in Rails. Threading is no different in Ruby than it is in other languages, with regard to guarding against concurrent access. If there is a section of code that should only be accessed in a serial fashion, control that access with a Mutex: m = Mutex.new m.synchronize do @foo.update @bar.count += 1 end Ruby provides a rich set of support beyond mutexes for dealing with threading issues, should you need them. Kirk Haines