Python GIL vs CAS

Chris Angelico rosuav at gmail.com
Thu Feb 15 12:12:33 EST 2018


On Fri, Feb 16, 2018 at 3:27 AM, Ned Batchelder <ned at nedbatchelder.com> wrote:
> On 2/15/18 9:35 AM, Chris Angelico wrote:
>>
>> On Thu, Feb 15, 2018 at 2:40 PM, Oleg Korsak
>> <kamikaze.is.waiting.you at gmail.com> wrote:
>>>
>>> Hi. While hearing about GIL every time... is there any real reason why
>>> CAS
>>> doesn't help to solve this problem?
>>>
>>> https://en.wikipedia.org/wiki/Compare-and-swap
>>
>> Because the GIL is not a problem. It's a feature. Before you ask about
>> solutions, you need to clarify what you are calling a problem :)
>>
>
> Let's not overstate the case.  The GIL is not a feature, it's an effective
> solution to a problem.  The Python interpreter has data that is shared among
> threads, including the state of the interpreter, and all of the reference
> counts of all of the Python objects.  When that data is modified, it must be
> done in a thread-safe way.  The GIL is a simple and effective solution to
> doing that correctly.

Okay, I kinda exaggerated. But the GIL isn't a "problem". As you say,
it's a simple way to achieve an important goal.

Removing the GIL from CPython *has* been done, more than once. Each
time, the alternative gave some performance improvements, and a number
of penalties.

ChrisA



More information about the Python-list mailing list