MRI Ruby 中的 GVL(Global VM Lock,以前称为 GIL)允许一次只有一个线程执行 Ruby 代码 — 所以线程不提供真正的 CPU 并行性。但 GVL 在 I/O 期间被释放,所以线程确实帮助 I/O 密集型工作。对于 CPU 并行性,你使用多个进程。这与 Python 的 GIL 情况类似。
GVL:一次一个线程运行 Ruby 代码
MRI (the standard Ruby) has a GLOBAL VM LOCK:
→ only ONE thread executes Ruby code at any instant (no CPU parallelism from threads)
→ BUT the GVL is RELEASED during blocking I/O (network, file, DB)
So: threads help for I/O-bound work, NOT for CPU-bound work.
