# Backgroundrb concurrent client access, results services

**URL:** <https://www.ruby-forum.com/t/backgroundrb-concurrent-client-access-results-services/109441>\
**Category:** Rails\
**Created:** [July 15, 2007, 12:37am UTC](https://www.ruby-forum.com/t/backgroundrb-concurrent-client-access-results-services/109441 "2007-07-15T00:37:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ghoti143](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/90db22/32.png) [@ghoti143](https://www.ruby-forum.com/u/ghoti143)\
**Post date:** [July 15, 2007, 12:37am UTC](https://www.ruby-forum.com/t/backgroundrb-concurrent-client-access-results-services/109441/1 "2007-07-15T00:37:43Z")

</div>

First thank to backgroundrb, it sure makes distribute computing a lot  
easier. A couple of questions:

1. I don’t fully understand the reason for Results services, can I just  
create instance vars, methods within the Worker class help to exposed  
shared result data? I did notice about results being alive after the  
Worker is deleted. Is this the only reason?

2. Continue with the first question, since I have no need to access data  
after the Worker is deleted, I rather not introduce additional book  
keeping. I want to introduce instance vars and methods to access data  
within the Worker. Will I have to worry data corruption/sync problem if  
I have multiple MiddleMan clients accessing the same Worker that may be  
calling instance vars and/or methods at the same time. Or if I just use  
the Results service, my worries goes away. I guess I will spend sometime  
soon digging into the codes to better understand it, but in the mean  
time any info would be greatly appreciated.

Thanks,  
Mike

---

<div class="post-metadata">

**Author:** ![ghoti143](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/90db22/32.png) [@ghoti143](https://www.ruby-forum.com/u/ghoti143)\
**Post date:** [July 15, 2007, 1:00am UTC](https://www.ruby-forum.com/t/backgroundrb-concurrent-client-access-results-services/109441/2 "2007-07-15T01:00:39Z")

</div>

On Jul 14, 2007, at 3:37 PM, Mike Hang wrote:

> data  
> soon digging into the codes to better understand it, but in the mean  
> time any info would be greatly appreciated.
> 
> Thanks,  
> Mike

Mike-

Stay away from the results worker and just use methods and instance  
variables. The results worker is only useful if you want to keep some  
results around after you kill your worker. ALso the results worker is  
a tad broken right now as well.

If you need to have multiple access to variables in a worker then  
you may need to synchronize access to instance variables and methods  
with a mutex. add a ‘lock’ helper method like this to your worker:

def lock  
@\_lock ||= Mutex.new  
@\_lock.synchronize { yield }  
end

And then use it every time you have an area of code that could get  
accessed by multiple clients at once:

def important\_method  
lock do  
# some important thing in here that only  
#should be accessed by one thread at a time  
end  
end

Cheers-  
– Ezra Z.  
– Founder & Ruby Hacker  
– removed\_email\_address@domain.invalid  
– Engine Y., Serious Rails Hosting  
– (866) 518-YARD (9273)
