[concurrency-interest] Possibly Offtopic - Java Concurrency/Parallelism adoption by Clojure
alex at puredanger.com
Sat Jan 29 16:55:06 EST 2011
Fork/join is not currently used in Clojure core. There is an
experimental version that provides support for parallel sequence
operations (filter, map, reduce, etc) over a fork-join pool (discussed
in David Liebke's talk at the Clojure Conj conference last year:
http://incanter.org/downloads/fjclj.pdf ) but it will evolve and
probably not be included in Clojure core for some time to come.
The concurrency model in Clojure is based primarily on immutable
(persistent) functional data structures. Immutability means all core
Clojure data structures to be thread-safe. Mutable state is supported
by the ref construct which provides identity and a reference to the
current version of an immutable data structure. Changes to refs are
protected by a software transactional memory system. To change one
(or more) refs you must create a transaction that is applied by the
STM and may retry. See http://clojure.org/refs for much more info.
There are also atoms (for uncoordinated synchronous state) and agents
(asynchronous uncoordinated state). Change requests are sent to
agents with either send (for CPU tasks) or send-off (for possible I/O
blocking tasks). Agent send is backed by
Executors.newFixedThreadPool() of size 2 + # processors. Agent
send-off is backed by an unbounded Executors.newCachedThreadPool().
Clojure also supports a "future" that will execute an arbitrary
function body (all Clojure functions implement Runnable and Callable)
in a separate thread and return an instance of Future. Clojure
provides a set of helper functions that expose all of the Future
methods (except timed get).
As far as I know, Scala uses fork/join underneath the Scala actor
pool. Also Fortress uses fork/join as the basis of its
Hope that helps...
Mohan Radhakrishnan wrote:
> I am a beginner and I have come across news that Fork/Join is
> reused by Clojure to support parallelism.
> I would like to know if the existing concurrency support ( Futures ? )
> are also reused. I am posting this here first because the JSR 166
> contributors might have been consulted by the Clojure developers.
More information about the Concurrency-interest