He mentions Python's GIL (which makes multi-threading completely useless), but Ruby (even 1.9) has a GIL too [1] that works exactly the same (awful) way. Ruby 2.0 will have it too [2]. A new Python implementation, unladen swallow is developped by Google to adress exactly this issue. Python-stackless avoids this problem, but the paraigm change is huge, 'normal' code has to be largely rewritten for stackless.
Note that, if I correctly understood, python event engine Twisted uses a custom C-implemented event loop to avoid this.
The GIL (in Python, can't speak about Ruby) is a controversial issue because people assume its bad and Python is therefore bad at concurrent programming etc. Without the GIL, the implementation would be drastically more complex and slower because all built in datatypes, dictionary lookups (for method lookups) etc would need to be made atomic, through locking. I think I can live with the GIL in this case - use threads for asynchronous (rather than parallel) code and use processes (and Python 2.6's multiprocessing library makes this easy) for parallel code execution.
Having said that, I welcome Google's unladen swallow and hope they succeed in removing the GIL.
That's not strictly true. Take a look at http://plausible.org/nasal for an example of an interpreter (mine) in the same broad space as Python and Ruby, yet without a global lock for anything but garbage collection (fixable -- there's no reason in principle preventing a concurrent GC from being dropped in). In tests of CPU-bound code without excessive allocation, it scales to 4-way SMP without trouble.
"""
Python has a GIL as opposed to fine-grained locking for several reasons:
--- It is faster in the single-threaded case.
--- It is faster in the multi-threaded case for i/o bound programs.
--- It is faster in the multi-threaded case for cpu bound programs that do their compute-intensive work in C libraries.
--- It makes C extensions easier to write: there will be no switch of Python threads except where you allow it to happen (i.e. between the Py_BEGIN_ALLOW_THREADS and Py_END_ALLOW_THREADS macros).
--- It makes wrapping C libraries easier. You don't have to worry about thread-safety. If the library is not thread-safe, you simply keep the GIL locked while you call it.
"""
Not really. Stackless Python still has a GIL, and if you want to make use of multiple threads, the GIL will still bite you.
Stackless allows you to write coroutines and has lots of cool abilities, but avoiding the GIL is simply not one of them as far as making use of multiple cores.
Why is everyone so concerned with multi-core concurrency withi languages like Python and Ruby? Adding another processor will get you, best case, a 2x speedup. Rewriting in, say, OCaml or Haskell will get you a 25x speedup.
Note that, if I correctly understood, python event engine Twisted uses a custom C-implemented event loop to avoid this.
[1] http://www.igvita.com/2008/11/13/concurrency-is-a-myth-in-ru...
[2] http://groups.google.com/group/comp.lang.ruby/msg/e809a7a720...
Wow, seems like MacRuby uses OS threads and completely abolished the GIL [3].
[3] http://www.infoq.com/news/2009/06/macruby-drops-gil-threadin...