From: mental@... Date: 2006-01-26T01:35:44+09:00 Subject: Re: LazyLoad Quoting Erik Veenstra : > > On the other end of things -- one issue that I've still got > > to address for myself in lazy.rb is threadsafety. So you've > > improved on mine in that respect. > > Well, there is a problem with my locking. Do you remember that > a set both Branch@items and Branch@snapshots in Branch#load, > like this?: > > @snapshots = lazy {load; @snapshots} > @items = lazy {load; @items} > > Both Lazy objects don't share the same Mutex object, so, > effectively, under these circumstances, there's no locking. Well, the way I would do it is to treat load as a single computation (which I'd be inclined to do for conceptual reasons, thread safety aside). That means something like: blah = lazy {load; [ @snapshots, @items ]} @snapshots = lazy { blah[0] } @items = lazy { blah[1] } (note that Array#[] forces the promise, so we add extra laziness) One computation, one promise, one mutex. -mental