From: Simon Krahnke Date: 2008-12-28T12:04:46+09:00 Subject: Re: Are all Ruby built-in objects thread safe? * Robert Klemme (11:52) schrieb: > On 27.12.2008 09:55, Simon Krahnke wrote: >> * Robert Klemme (11:23) schrieb: >> >>> if hash.contains_key? k >>> dat = hash[k] >>> else >>> dat = create_dat(k) >>> hash[k] = dat >>> end >> >>> [...] >> >>> So in this case you need a lock around the _complete_ block of code. >>> (Note, the method level lock would work if using a Hash with a default >>> block, but this solves only a small portion of the cases.) >> >> If Hash had a method get_with_default that took a default value or a >> block like initialize you could solve these cases. > > Please read my note: this was just an example for the class of > synchronization problems that cannot be solved within the class. You > can invent arbitrary more complex scenarios that would not make any > sense to be covered by a standard method in class Hash. Well, my point is it's a bad example. You are asking an object questions to base your actions on the object on. Don't ask, tell. :-) > Put it differently: in concurrent applications there are many scenarios > where lock granularity "method" is insufficient to guarantee correct > code. Instead you need explicit locking for larger portions of _client_ > code. That might be, I'd like to see a good example. mfg, simon .... i'm not killfiled?