Hi Meikel, On Sat, Mar 13, 2010 at 10:51 PM, Meikel Brandmeyer <m...@kotka.de> wrote:
> On Fri, Mar 12, 2010 at 08:27:15PM +0100, Christophe Grand wrote: > > > See my memoize5: the call isn't computed inside the swap!s > > That doesn't mean, that it is not computed several times! > I agree: it can be concurrently computed several times (but a given thread would only compute it at most once). I'm sory: I read too quickly and didn't understand that you were concerned about the computation happening only once for all threads. > > Since you use a lock I think some clever combination of memoized > functions > > can create a deadlock. > > No. In the protected area we simply create a promise and fire off a > thread, which does the computation. Then we return immediatelly. So no > deadlock possibility here. However we trade one lock for the „other“ > (the promise). What is the possibility of a deadlock here? Well, the > computation of f never completes. But this is not a problem of memoize. > The only way memoize could cause a problem here is that the computation > of f somehow calls f again with the same arguments. Then it would > deadlock on the promise, but without memoize we would also have a > infinite loop here... > You're right of course. I apologize. As a minor note: couldn't a future replace your promise? Or couldn't you get rid of the other thread and deliver the promise in the same thread but outside of the (locking ..) form? Hmm or even a delay!? Ok I tried to used delays. So I slightly modified my memoize5 (see memoize6) and I built on that a memoize7 which enforces (through delays) that a value is onlycomputed once (except if the strategy previously removed it from the cache of course). Do you see a problem in my latest implementation? http://gist.github.com/330644#LID153 Thank you, Christophe -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en