From: Brian Candler Date: 2004-09-11T01:42:31+09:00 Subject: Re: Variable scoping > 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. | 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.