From: Ara.T.Howard@... Date: 2004-09-11T02:35:01+09:00 Subject: Re: Variable scoping On Sat, 11 Sep 2004, Brian Candler wrote: >> This is because you have never read ruby-man-1.4, and it's very bad :-) > > You mean very bad of me not to read it? Fair enough. I _have_ read quite a > lot though :-) Besides, we can all make mistakes. well - not guy really ;-) > | while TRUE > | ns = gs.accept > | print(ns, " is accepted\n") > | Thread.start do > | s = ns # save to dynamic variable > > But isn't there a race there? That is, if the interpreter context-switches > after the Thread.start, goes back around the loop, and ns is assigned to a > new object before "s = ns" is executed. > > I think for safety you should do > > Thread.start(ns) do |s| > > But that's the trouble with this thread-safety stuff. Maybe 999 out of 1000 > times the previous code would work. It's almost certainly not possible to > catch that sort of problem with unit-testing, unless you splatter "sleep"s > all over the code when testing. > > Some sort of static indication of a possible problem would be very useful. > > It would have to be able to tell that: > - you are using a variable within a Thread .... block > - the variable may be assigned to again by the other thread > (which, in this case, is an *earlier* assignment because it's in a loop) > > Regards, > > Brian. why not fork? it's not that expensive anymore and would solve most of your problems. -a -- =============================================================================== | EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov | PHONE :: 303.497.6469 | A flower falls, even though we love it; | and a weed grows, even though we do not love it. | --Dogen ===============================================================================