Wes Gamble wrote:
> Wes Gamble wrote:
>> All,
>> 
>> I'm reading through the Pickaxe book on synchronization and threading. 
>> I want to have a method that will basically put a MAX() value from a 
>> table and I want to ensure that two threads don't execute this code at 
>> the same time.
>> 
>> I'm thinking I can just have my object descend from Monitor (< Monitor) 
>> and then put "synchronize" around the relevant code, like so:
>> 
>> class myClass < Monitor
>> ...
>> 
>> def get_max_value
>>   synchronize { max_value = do_select_to_get_max_value }
>>   max_value
>> end
>> 
>> This should work just fine - correct?
>> 
>> Thanks,
>> Wes
> 
> There is an admonition in the Pickaxe book that says "In both the class 
> form and when including MonitorMixin in an existing class it is 
> essential to invoke super in the class's initialize method."
> 
> I want my sychronization to occur in a class method.  So that would seem 
> to obviate the need for the super in the "initialize" block.  Am I 
> correct?
> 
> Thanks,
> Wes


Yeah, I definitely want the synchronization at the class level - do I 
extend the class object directly instead of doing an "include 
MonitorMixin"?

Wes

-- 
Posted via http://www.ruby-forum.com/.