- Global Interpreter Lock
Global Interpreter Lock (abbr. GIL) is a
mutual exclusion lock held by aprogramming language interpreter thread to avoid sharing code that is notthread-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:
* Python (precisely, its C implementation,CPython [cite web
url=http://www.ddj.com/linux-open-source/206103078?pgno=2
title= Concurrency and Python
publisher=Dr. Dobb's Journal
quote="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."
date=2008-02-03
accessdate=2008-07-12] [ [http://docs.python.org/api/threads.html Python/C API Reference Manual: Thread State and the Global Interpreter Lock] ] )
* Ruby (where it is called Global VM Lock).References
See also
*
Green threads
Wikimedia Foundation. 2010.