2

i wonder if the multi threading in python/ruby is equivalent to the one in java?

by that i mean, is it as efficient?

cause if you want to create a chat application that use comet technology i know that you have to use multi threading.

does this mean that i can use python or ruby for that or is it better with java?

thanks

never_had_a_name
  • 90,630
  • 105
  • 267
  • 383

3 Answers3

10

This is not a question about Ruby, Python or Java, but more about a specific implementation of Ruby, Python or Java. There are Java implementations with extremely efficient threading implementations and there are Java implementations with extremely bad threading implementations. And the same is true for Ruby and Python, and really basically any language at all.

Even languages like Erlang, where an inefficient threading implementation doesn't even make sense, sometimes have bad threading implementations.

For example, if you use JRuby or Jython, then your Ruby and Python threads are Java threads. So, they are not only as efficient as Java threads, they are exactly the same as Java threads.

Jörg W Mittag
  • 363,080
  • 75
  • 446
  • 653
3

Both Ruby and Python use a global interpreter lock. The issue is discussed in detail here: Does ruby have real multithreading?

Community
  • 1
  • 1
philosodad
  • 1,808
  • 14
  • 24
  • 2
    This is not true. Neither the Ruby Language Specification, nor the Python Language Specification say anything about a Global Interpreter Lock. And, in fact, only two Ruby Implementations and only one Python Implementation have a GIL. – Jörg W Mittag Jun 03 '10 at 12:30
  • 2
    @JörgWMittag Saying "This is not true" as a first line is misleading. The "only" implementations with GIL are the _official_ ones. For day to day conversations it's only fair to assume people are talking about MRI/YARV/CPython without any specified quantifier. So the statement "Ruby and Python use GIL" is practically acceptable unless you go deep. – kizzx2 Nov 18 '12 at 06:13
  • @kizzx2: I admit I am not that intimately familiar with Python, but in Ruby, there is no such thing as an "official" implementation. There is a language specification and every implementation that complies with that specification is every bit as "official" as any other one. You mentioned MRI: MRI *doesn't* have a GIL, so it actually *strengthens* my point. – Jörg W Mittag Nov 18 '12 at 12:23
  • 2
    @JörgWMittag YARV is what you get when you visit the obvious http://ruby-lang.org, or `apt-get`/`yum`/`ports`/`brew`/ `install ruby` on your favorite platform. Saying there is no such thing as official implementation is simply an ivory tower / non-practical perspective. Like saying OpenOffice is as official as MS Office because OOXML is published, or like Mono is as official a .NET CLR as the MS implementation. Regarding MRI: Of course GIL wouldn't make a lot of sense in MRI 1.8, so you win on that one. – kizzx2 Nov 18 '12 at 13:42
1

philosodad is not wrong to point out the constraint that the GIL presents. I won't speak for Ruby, but I am sure that it's safe to assume that when you refer to Python that you are in fact referring to the canonical cPython implementation.

In the case of cPython, the GIL matters most if you want to parallelize computationally intensive operations implemented in Python (as in not in C extensions where the GIL can be released).

However, when you are writing a non-intensive I/O-bound application such as a chat program, the efficiency of the threading implementation really just doesn't matter all that much.

Jeremy Brown
  • 17,880
  • 4
  • 35
  • 28