Thread-safe way to add a key to a dict only if it isn't already there?

Chris Angelico rosuav at gmail.com
Sun Jul 8 15:05:18 EDT 2018


On Mon, Jul 9, 2018 at 4:57 AM, Marko Rauhamaa <marko at pacujo.net> wrote:
> Chris Angelico <rosuav at gmail.com>:
>
>> On Mon, Jul 9, 2018 at 2:11 AM, Marko Rauhamaa <marko at pacujo.net> wrote:
>>> MRAB <python at mrabarnett.plus.com>:
>>>> In C you'd declare 'quit' as 'volatile' to tell the compiler that it
>>>> could change unexpectedly, so don't make that assumption.
>>>
>>> C is an even tougher case. Even if the compiler kept on checking a
>>> volatile value, the CPU might never propagate the cache content to
>>> the other core. You'd need a memory barrier. In Java, "volatile"
>>> effectively creates a memory barrier, but in C (and C++) it does not.
>>> In C you need something like a mutex to see the effects of other
>>> threads running.
>>>
>>> (BTW, I think that's a terrible thing for the C standards committee to
>>> specify.)
>>
>> None of this has any impact on Python whatsoever.
>
> [citation needed]
>

Why? You might as well say "in Blurple, all integers greater than 5
compare equal to each other, and it's possible to implement a Python
interpreter in Blurple, therefore we can't trust integer comparisons
in Python". It's ridiculous to consider. The languages are completely
independent.

Are you assuming that Python's semantics are defined by the semantics
of one possible implementation language?

ChrisA



More information about the Python-list mailing list