Nobody understands the GIL - Part 3: Thread Safety
Published on June 21, 2013 by Jesse Storimer
There are some misconceptions in the Ruby community about this question surrounding MRI's GIL. If you only take one thing away from this article today, let it be this: The GIL does not make your Ruby code thread-safe.
But you shouldn't take my word for it.
This series started off just trying to understand what the GIL is at a technical level. Part 1 explained how race conditions could occur in the C code that's used to implement MRI. Yet, the GIL seemed to eliminate that risk, at least for the
Array#<< method we looked at.
Part 2 confirmed that the GIL did, in fact, make MRI's native C method implementations atomic. In other words, these native implementations were free from race conditions. These guarantees only applied to MRI's native C functions, not to the Ruby that your write. So we were left with a lingering question:
Does the GIL provide any guarantee that your Ruby code will be thread-safe?
Read the full article on RubyInside.com.