
Ask YC: What Language Do You Use for Multiple CPUs? - bcater

======
crucini
The real question is, "what process model do you use for multiple CPUs?"
Assuming a Unixy OS, you can use threads or multiple processes.

If you choose multiple processes, you have to intelligently use IPC to
coordinate them. But you can happily use pretty much any language.

If you choose threading, scripting languages are problematic. For example,
Python has a Global Interpreter Lock. In that case, I think the only "safe"
choices are C++ and Java. Java's safe because its "synchronized methods"
enforce locking, often in a wasteful manner. C++ leaves the entire
synchronization problem in your lap, giving you infinite room for performance
and for subtle and maddening bugs.

Multi-process is generally a better approach than threading. I've seen too
much time spent debugging threaded apps to ever recommend that approach. Every
hour poured into debugging a deadlock, or worse yet, a mysterious cross-thread
heap trampling is an hour taken away from improving the product.

------
dfranke
Haskell is excellent for parallel processing -- probably as good as Erlang if
you're just talking about multiple cores on one system and not distributed
processing.

------
sohail
I've used C++ for multiple CPUs and multiple machines. Quite easy really. Most
people just make it too complicated I think.

------
queensnake
Intel has made a library (TBB) and language (Ct) (both based on C++) that
tackle different subsets of how you might want to use parallelism.

<http://blogs.intel.com/research/2007/11/q4_itj.php>

------
ayc
SP-Forth (<http://spf.sourceforge.net/>) to program multithreaded
applications, such as acWEB, acSMTP [.sf.net], Eserv/3 (
<http://www.eserv.ru/> ) internet servers.

------
Elfan
I just want to second what what several others have implied about Erlang. It
makes the actor model feel right to the point that the fact that your program
can run on multiple cores/cpus/computers is seems incidental.

------
carpal
Ruby/Rails/Mongrel/Pound does a great job of utilizing all those CPUs that I
have in a production environment. There's a bunch of overhead, but it is
easier than having to deal with locking.

It really depends on your application, though. If it isn't a web application,
and state matters, then you're going to have to go elsewhere.

------
ivankirigin
Design software to run in multiple processes & threads, and you'll be fine for
both multi-core and multi-cpu.

Most interesting systems have multiple dynamically interacting processes, but
this might be a bias of mine from the robotics world.

------
bcater
I was hoping that Python threads split across processors, but it seems that
they don't. Is there a language that does it "automagically" without having to
explicitly code it?

~~~
jey
No, the standard Python interpreter kind of sucks at this. You might want to
look at Stackless Python though, it has all sorts of neat concurrency
primitives. <http://www.stackless.com>

~~~
euccastro
Stackless is great, but it doesn't help much with multiple processors.

------
yariv
Erlang

------
vmcodes
I believe Erlang does.

------
boucher
Java, C/C++/Objective-C. Many others.

------
zurla
lolcode

------
downer
C and C++ using shared state, but minimizing locking by being clever (e.g.,
subdivide first).

