5 ms·
MRI still has the global interpreter lock, i.e. is effectively single-threaded for CPU-bound tasks. IO/waiting for forked jobs can be done in background thread
by the8472 12y ago
MRI still has the global interpreter lock, i.e. is effectively single-threaded for CPU-bound tasks.
IO/waiting for forked jobs can be done in background threads since the lock is released on some select function calls.
So while incremental GC certainly does bring down latency caused by the GC it does not bring down latency for tasks that could be parallelized.
- chrisseaton 12y agoMRI is multi-threaded, even for CPU-bound tasks - it just doesn't run those threads in parallel.
- nitrogen 12y agoHence the "effectively" in the parent comment; Ruby's interpreter lock can be very problematic in threaded apps that use I/O functions from C-based gems that forget to release the lock.
- chrisseaton 12y agoIt's not a case of 'effectively' or not. MRI is 100%, totally, unequivocally, multi-threaded. The fact that those threads do not run in parallel is an entirely unrelated issue. Parallelism is not an essential quality of multi-threading.
- canadev 12y agoI don't understand what this means... Can you explain? Here's my basic understanding: MRI is a single process, with multiple threads... They can't run in parallel because of the global interpreter lock (which is used because the code in MRI is not thread safe? Meaning each thread can touch the same memory and may leave it in a broken state for another thread, so we lock access to it first...). So: there are multiple threads, I am guessing each with their own task (maybe one to run the code, one to do garbage collection, ... I have no idea), but because of the GIL they can't be parallelized. Still multi-threaded anyway.
- nitrogen 12y agoYou can create multiple OS-level threads in MRI using Thread.new. Those threads can run code at the same time, just not Ruby code. There is a function that C extensions are supposed to call while running I/O that can block, or while running CPU-intensive non-Ruby code, that releases the global lock.
- teacup50 12y agoThis is a completely pointless semantic distinction that nobody cares about. What makes threads interesting is parallelism; if the goal is merely cooperative or pre-emptive multitasking, where there's no concurrency, then you're "effectively" not multi-threaded as per any modern expectation.
- chrisseaton 12y agoIf threads aren't interesting except for parallelism, what do you think people were using them for the multiple decades when the vast majority of people were running single-cored uniprocessor systems? The answer is that it's often useful to manage multiple things at the same time, even if we can't or don't want to actually do them at the same time. We may want to use blocking IO for the simplicity it gives us compared to asynchronous IO, but allow other parts of the system to continue to run during that blocking. We may want to let threads and the kernel manage our context and context switches for us, instead of manually storing and restoring state, because it can be simpler that way.
- teacup50 12y ago> If threads aren't interesting except for parallelism, what do you think people were using them for the multiple decades when the vast majority of people were running single-cored uniprocessor systems? They largely weren't. POSIX threads weren't standardized and widely adopted until the 90s, and it wasn't until multi-processor systems became more prevalent that threads saw wide adoption at all.
- nitrogen 12y agoIf you write a C extension to do CPU-intensive stuff, you can release the lock.