GVL (Global VM Lock, ਪਹਿਲਾਂ GIL) MRI Ruby ਵਿੱਚ ਸਿਰਫ ਇੱਕ thread ਨੂੰ Ruby code ਨੂੰ ਇੱਕ ਵਾਰ ਵਿੱਚ execute ਕਰਨ ਦਿੰਦਾ ਹੈ — ਇਸ ਲਈ threads ਸਚਮੁਚ CPU parallelism ਪ੍ਰਦਾਨ ਨਹੀਂ ਕਰਦੇ। ਪਰ GVL I/O ਦੇ ਦੌਰਾਨ release ਹੋ ਜਾਂਦਾ ਹੈ, ਇਸ ਲਈ threads ਅਸਲ ਵਿੱਚ I/O-bound ਕੰਮ ਲਈ ਮਦਦਗਾਰ ਹਨ। CPU parallelism ਲਈ, ਤੁਸੀਂ ਕਈ processes ਵਰਤੋ। ਇਹ Python ਦੀ GIL ਸਥਿਤੀ ਨੂੰ mirror ਕਰਦਾ ਹੈ।
GVL: ਇੱਕ ਵਾਰ ਵਿੱਚ ਇੱਕ thread Ruby code ਚਲਾਉਂਦਾ ਹੈ
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.
