From: khaines@... Date: 2006-09-05T17:25:00+09:00 Subject: Re: The real difference between Mutex and Sync On Tue, 5 Sep 2006, Kent Sibilev wrote: > This patch will make Mutex a bit slower, but much better in terms of > garbage collection: > > Index: lib/thread.rb > =================================================================== > RCS file: /src/ruby/lib/thread.rb,v > retrieving revision 1.16.2.2 > diff -r1.16.2.2 thread.rb > 99c99 > < @waiting.push Thread.current > --- >> @waiting.unshift Thread.current > 115c115 > < t = @waiting.shift > --- >> t = @waiting.pop While I am not benchmarking with performance in mind, that change doesn't seem to have any significant effect on overall speed, which doesn't surprise me. Speed-wise, it is just flipping the location of the expensive array operation from the unlock to the lock. And yes, that simple change does seem to make a significant difference, because pop will realloc the array. Kirk Haines