OCaml and Threading

Coincidentally, someone posted a link to this message from 2002 where Xavier Leroy explains why they won’t implement multiprocessing in OCaml. It’s interesting to reconsider his arguments 8 years later. He says there are three reasons to use parallelism:

  1. Make use of multiple processors: OCaml does not support this.
  2. Overlapped I/O: Multiple threads can block on I/O, but only one thread can execute at a time. OCaml supports this.
  3. Coroutines: User-level scheduling or call/cc provides this. OCaml supports this.

So the only issue is #1. Towards the end of the message, he basically dismisses the idea that multiprocessors will ever be popular: “I believe [hyperthreading is] the last convulsive movement of SMP’s corpse.” He doubts that one could get good performance due to locking issues. Therefore, he says the extra implementation complexity just isn’t worth the small performance boost.

Today multiple cores are the primary way Intel/AMD will deliver higher performance. There’s demand for languages that can use cores efficiently (and provide nice abstractions). There are now many efficient concurrent runtimes and garbage collectors, many of which use lock-free algorithms. It’s still complex to implement, but not terribly so for the smart guys running the OCaml project. It’s still unlikely they would ever implement multiprocessing now, but new languages should tackle multiprocessing from the beginning.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s