On Sun, 30 Dec 2012 13:43:53 +0100, Matthew Kerwin <matthew / kerwin.net.au> wrote:
> So does that mean these are functionally identical?
>
>     Thread.new(a) { |b| do_something_with b }
>
> .. and ..
>
>     Thread.new { b=a; do_something_with b }
>
> Or is there a potential race condition caused by possibly deferred
> execution of the block, which is avoided by performing the "renaming"
> assignment in the parent thread?  I'm trying to think of an example, but am
> having trouble.

There's another thing apart from the race conditions. These are mostly equivalent (except for what you've already said) only if there is no variable called `b` in the outer scope - if there was one, in your second example `b=a` will assign to it and change the value outside the thread. In the first case, the "outer" `b` will simple be inaccessible inside the thread, but its value outside the thread won't be changed.

(The above only applies to Ruby 1.9 and newer, the semantics for both versions on 1.8 are the same - if there is an "outer" b, its value will change. This is obviously not always what the coder has intended and so it was changed in 1.9.)

-- 
Matma Rex