From: Wladimir Mutel Date: 2002-03-30T00:32:55+09:00 Subject: Re: Threads in Iterators � ������ <001d01c1d6c0$26318910$dd31200a@JAZZ> Norman Makoto Su �������(�): >> If you are concerned about this, then use a mutex around code that might >> corrupt your data: >> >> m = Mutex.new >> arr.each do |val| >> @mutex.synchronize do >> vals << val >> end >> end >> >> I think appending onto vals like this should be an atomic operation (so >> the mutex isn't necessary), but if you had a non-atomic operation, then >> you would definitely need a mutex. > > How do I know what operations are atomic operations in ruby? I guess I should > assume, unless explicitly specified, that all operations in ruby are not atomic. Builtin library methods might be made reentrant/atomic with their side effects, but they are too easy to redefine, so may be you should not rely on that much and do your own syncronization with mutexes.