Global Interpreter Lock

From Wikipedia, the free encyclopedia

Global Interpreter Lock (abbr. GIL) is a mutual exclusion lock held by a programming language interpreter thread to avoid sharing code that is not thread-safe with other threads. There is always one GIL for one interpreter process.

Usage of a Global Interpreter Lock in a language effectively limits concurrency of a single interpreter process with multiple threads -- there is no or very little increase in speed when running the process on a multiprocessor machine.

The reasons of employing such a lock include:

  • increased speed of single-threaded programs (no necessity to acquire or release locks on all data structures separately)
  • easy integration of C libraries that usually are not thread-safe.

Applications written in languages with a GIL have to use separate processes (i.e. interpreters) to achieve full concurrency, as each interpreter has its own GIL.

Languages that implement a Global Interpreter Lock are, among others:

[edit] References

  1. ^ Python/C API Reference Manual: Thread State and the Global Interpreter Lock