Global Interpreter Lock

From Seo Wiki - Search Engine Optimization and Programming Languages

Jump to: navigation, search

A Global Interpreter Lock (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. Due to signaling with a CPU-bound thread, it can cause a significant slowdown, even on single processors[1].

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:


  1. David Beazley (2009-06-11). "Inside the Python GIL". Chicago: Chicago Python User Group. Retrieved 2009-10-07. 
  2. Shannon -jj Behrens (2008-02-03). "Concurrency and Python". Dr. Dobb's Journal. p. 2. Retrieved 2008-07-12. "The GIL is a lock that is used to protect all the critical sections in Python. Hence, even if you have multiple CPUs, only one thread may be doing "pythony" things at a time." 
  3. Python/C API Reference Manual: Thread State and the Global Interpreter Lock

See also

pl:Global Interpreter Lock

Personal tools

Served in 0.394 secs.