Thanks for the reply Timothy! I'll look into the future things :). The main reason for using refs was because I am constructing a contact network between different refs (a graph, consisting of nodes and edges.), which changes over time (all the short-term and long-term relations between hosts being started and breaking down again). If two of my refs start a steady relation together, I want a guarantee that one refers to the other in its :steady key, and the other refers to the one. So it seemed to me that both have to change simultaneously. I don't want host 1 to start initiating a steady relationship with host 2, while at the same time host 2 is starting one with host 3. I wrote an earlier version of this model with agents, but couldn't see how to guarantee bidirectional edges in a concurrent situation.
On Feb 26, 12:59 pm, Timothy Pratley <timothyprat...@gmail.com> wrote: > Hi Boris, > > > (doseq [e [retire-host slowdown-host infect-hosts naturalrecovery- > > host pair-host breakup-host] i world] > > (send-off (agent nil) (fn [_] (e i)))))) > > > There doesn't seem to be any concurrency happening, and the whole > > thing just slows down to not doing much at all. > > This code will create potentially (count world) threads 10000. Just > using send instead of send-off would possibly speed things up a lot as > it will limit the number of threads. Also creating a new agent every > time just to provide a thread is not economical. You could instead > have a small pool of agents and reuse them. Or you could take > advantage of futures which have been recently added to run the task > without an agent at all: > (doseq [e [r s i n b] i world] (future (e i))) > Also you might consider using (comp) to compose the set of e into one > function, which will reduce the amount of dispatches. Lastly, why do > you say you have to use refs here? It isn't obvious to me from the > code - the world locations look like they could be agents - but I'm > probably missing something, its quite complex :) > > Regards, > Tim. --~--~---------~--~----~------------~-------~--~----~ 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 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 -~----------~----~----~----~------~----~------~--~---