Note that there are some explanatory texts on larger screens.

plurals
  1. PORuby/Rails thread safety
    text
    copied!<p>I have been hacking with Ruby from time to time, but I haven't done anything big or multithreaded with it. I have heard that MRI only supports green threads and JRuby supports native threads via JVM. However, I stumble upon comments on blogs and discussion groups which say that "Rails is not thread-safe" or that Ruby itself is not thread safe. For example someone commented that there is a problem with the require statement. That sounds a bit fundamental. </p> <p>I have seen a lot of Java apps which don't handle concurrency properly and I have nightmares about them from time to time :-) But at least you <em>can</em> write thread-safe applications in Java if you <em>really</em> know what you are doing (it's just not easy). </p> <p>This all sounds quite alarming, can someone elaborate more - what is exactly the problem and how Rails manages to work at all if this is the case? Can I write multithreaded Ruby code which works correctly without race conditions and deadlocks? Is it portable between JRuby and MRI or do I have to hack in JVM specific code to take advantage of the JVM native threads properly?</p> <p>EDIT:</p> <p>I should have asked two questions, because people only seem to answer the rails threading stuff (which is nice in itself) and green threading vs. native threading. My concerns on core Ruby issues about thread <em>safety</em> haven't really been addressed. There seems to be at least an (unresolved?) <a href="http://www.daniel-azuma.com/blog/view/z4oi2c3bf8t16s/ruby_threads_and_kernel_require" rel="noreferrer">issue</a> with require in certain cases.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload