Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > My threading concern.

Reply
Thread Tools

My threading concern.

 
 
Aaron Rustad
Guest
Posts: n/a
 
      04-09-2005
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.

thanks!
AR.

 
Reply With Quote
 
 
 
 
Kirk Haines
Guest
Posts: n/a
 
      04-09-2005
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

 
Reply With Quote
 
 
 
 
Nicholas Seckar
Guest
Posts: n/a
 
      04-09-2005
On Saturday 09 April 2005 15:29, Aaron Rustad wrote:

> The reason stems from the ApplicationController of Rails, when a
> request is received


[continuing] a new Controller instance is created, and the related instance
variables are those of this new instance. A controller instance is not reused
for multiple requests.

If you'd like to read the source, see actionpack/lib/action_controller/base.rb
Look for "def process" -- it a class method of Controller.

--

Nicholas Seckar aka. Ulysses


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: threading in PyQt vs threading in standard library Steven Woody Python 0 01-09-2009 07:48 AM
threading in PyQt vs threading in standard library Steven Woody Python 0 01-09-2009 07:15 AM
Cooperative threading preemptive threading - a bit confused failure_to@yahoo.co.uk Java 9 12-29-2007 01:10 AM
Threading question Frederick Wilson Firefox 1 12-22-2004 12:23 AM
Threading problem Fred Wilson Firefox 1 12-04-2004 01:39 AM



Advertisments