C
Charles Comstock
I just discovered a pattern that I have found to be quite useful. In
essence it allows for me to do automagically instantiation of variables
for a specific type. I have found it to be particularly useful in code
that has multiple mutex locks. For instance:
mlock = Hash.new {|h,k| h[k] = Mutex.new }
then later throughout my code when I need mutex I say
mlock["entry"].synchronize do
# blah
end
or
mlock["exit"].synchronize do
# exit blah
end
It's nice because that way I don't have to keep instantiating new
mutexes in the initalization code, I just add one whenever I need it.
Anyway, I thought it was a useful hack and thought I would share it.
Charlie
essence it allows for me to do automagically instantiation of variables
for a specific type. I have found it to be particularly useful in code
that has multiple mutex locks. For instance:
mlock = Hash.new {|h,k| h[k] = Mutex.new }
then later throughout my code when I need mutex I say
mlock["entry"].synchronize do
# blah
end
or
mlock["exit"].synchronize do
# exit blah
end
It's nice because that way I don't have to keep instantiating new
mutexes in the initalization code, I just add one whenever I need it.
Anyway, I thought it was a useful hack and thought I would share it.
Charlie