From: nobu.nokada@... Date: 2003-10-09T07:36:33+09:00 Subject: Re: Standard Queue Implementation and Thread Safety Hi, At Thu, 9 Oct 2003 03:49:48 +0900, Pete Kazmier wrote: > The implementation is essentially backed by an Array. Queue provides > synchronized push and pop methods (using Thread.critical), but methods > such as clear, length, and empty? are not synchronized. What happens > if one thread is in the middle of clearing the queue and then another > comes along to add/remove something from the queue? Why don't these > other methods need synchronization? Is Array thread-safe by default? Yes. Builtin methods (more accurately, not written in Ruby) are thread-safe, unless GC runs. Since Array#empty? and Array#length don't modify anything, and Array#clear just releases but requires no memory, GC doesn't get run. -- Nobu Nakada