From: Csaba Henk Date: 2005-02-27T19:54:58+09:00 Subject: Re: assignments and thread safety On 2005-02-27, nobu.nokada@softhome.net wrote: > Hi, > > At Sun, 27 Feb 2005 17:43:47 +0900, > Yohanes Santoso wrote in [ruby-talk:132474]: >> > Is "$a ||= 1" thread safe? I'd guess so, as "||=" is one piece of >> >> It is not guaranteed to be thread-safe, although in current official >> ruby vm it is 'atomic'. > > It is impossilbe. > > What do you expect for: > > $a ||= very.long.operation? Well, I had there "$a ||= 1", and fetching 1 is not a very.long.operation. But I see the point... even if concretely with 1 being the assinged value, "$a ||= 1" happens atomically (which could be the case for other literals and variables on the right hand side), it's necessarily accidental, so to say. "||=" can't have the value of the right hand side at its invocation... Csaba