From: Joel VanderWerf Date: 2003-10-09T14:03:13+09:00 Subject: Re: Standard Queue Implementation and Thread Safety nobu.nokada@softhome.net wrote: > 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. So Array#push is not thread-safe, but Queue#push is, right? I understand that Array#push could provoke a GC, but why would GC cause a context-switch?