5 ms·
I would rather recommend chapter on deterministic concurrency in this paper: http://community.haskell.org/~simonmar/par-tutorial.pdf http://community.haskell.or
by miga 14y ago
I would rather recommend chapter on deterministic concurrency in this paper: http://community.haskell.org/~simonmar/par-tutorial.pdf http://community.haskell.org/~simonmar/par-tutorial.pdf
[In particular `par` and promises.]
This solution is quickest to debug, and most efficient. One can also use multiprocessing-like approach:
http://docs.python.org/2/library/multiprocessing.html http://docs.python.org/2/library/multiprocessing.html
My last 15 years of practice indicate that other approaches lead to unnecessary complication, and are less likely to be effective (threads and semaphores in particular.)
- JoeAltmaier 14y agoThat! Message passing is a reasonable approach. Its particularly simple to design, and deadlock-free if message processors don't block on further messages. Drawbacks: Simplest when each message class (or queue) has one thread to handle it. But that doesn't optimize for available hyperthreads.
- pron 14y agoMessage passing is often insufficient without a centralized concurrent data structure (a database can serve that purpose). That is why Erlang has ETS (but that only guarantees isolation for single entity transactions), and Akka and Clojure have STM (and the Java concurrent data structures).
- swah 14y agoIs there something preventing people from writing correct, multi-threaded apps in Clojure (and kicking Python/Rubys asses)?
- pron 14y agoNo. Python/Ruby/Javascript don't even come close to JVM performance even without multi-threading, though.
- FreezerburnV 14y agoClojure actually has a lot of stuff in its design specifically for multithreading. Like the GP post said, Clojuer has Software Transactional Memory (STM) on top of immutable data structures to make messing up multithreaded programs hard, and you'd almost have to deliberately do so. And yes, like another reply says, Clojure (and pretty much anything that's designed well and runs on the JVM) is much, much faster than Python/Ruby by default. A lot of this has to do with the JIT compiler that Java has been working on for a long time, which Python/Ruby don't have outside of an PyPy implementation. Also Python/Ruby don't have access to actual threads by default, because it has a global lock. They run everything basically in a single thread.
- swah 14y agoThat is exactly my question. If Clojure has got great performance and great multithraeding support, why haven't it gained a greater share of the dynamic languages market?