On 14.09.2008 19:27, David Masover wrote:
> On Sunday 14 September 2008 03:24:53 Robert Klemme wrote:
>> In a farmer worker scenario (or however you call it)  
>> the farmer distributes work and is also often responsible for collecting 
>> results.  If there is no work left he needs to notify workers of this 
>> fact so they can react appropriately (die).
> 
> I'd like to detect "no work left" as a case of the "farmer" going out of 
> scope, if possible.

There is no hook in Ruby that is called when the scope of a variable 
ends.  An object without any references can be garbage collected.  But a 
finalizer won't work because then the object is gone already.  Also, the 
queue that connects farmer and workers will still have references even 
if the farmer is gone, so the finalizer will never be called...

> So, it sounds like you're telling me all the "usual" ways of doing this.

What's wrong with using the usual ways?

> Is there no way to make my suggestion work?

You can use begin ensure end.  This will guarantee that action will be 
taken even in case of an exception.  If that's what you're after.

Cheers

	robert