On Jan 2, 4:03 pm, ianp <ian.phill...@gmail.com> wrote: <snip> > Yes, exactly. This is the problem with a Java based version (at least > with one that uses the standard collections libraries). At the very > least your reporting function would have to make a complete copy of > the world state while holding the lock, it could then go in to process > this and produce the report on another thread after releasing the > lock. > > This is why persistent data structures are so cool: you gain the > ability to look at consistent snapshots of the world for free. > > Cheers, > Ian.
In this particular case, the STM system is more important than the fact that it uses persistent data structures. A Java solution that didn't have persistent data structures but still had an equivalent STM could use copy-on-write: it would certainly be slower, but I think it would work just fine (the data structures are quite small). I think the hardest part for a traditional Java solution would be to see a consistent snapshot of the ant world without impeding all other threads. Having a global lock would certainly work, but implies impeding all threads to draw the ant world (or to update any edge in the graph). You don't necessarily need a global lock, but the alternative would be to stripe the lock into several locks: at the extreme to have a read- write lock for every place in the ant-world. Then always acquire those locks in the same order (to avoid deadlock). The UI thread would then have to acquire all the locks to see a consistent world (hence impeding all threads). Now to increase concurrency you might want to keep some history around for the UI thread... :-) Step-by-step you are "Greenspunning" Clojure's STM inside your Java ants demo... In fact, I think a neat demonstration for your talk would be to start with a naive Java solution with a global lock. Then introduce a read- write lock. Then stripe it in say 4 locks, then 8, then one for each "ref". Then start adding history to avoid stopping the world. You should probably stop before having implemented the STM ;-) End up the demo explaining what Clojure's STM does and the interplay between persistent data structures and STM (e.g. the price of keeping history). /Karl -- 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