Is there a more efficient threading lock?

Chris Angelico rosuav at gmail.com
Tue Feb 28 20:58:54 EST 2023


On Wed, 1 Mar 2023 at 10:04, Barry <barry at barrys-emacs.org> wrote:
>
> > Though it's still probably not as useful as you might hope. In C, if I
> > can do "int id = counter++;" atomically, it would guarantee me a new
> > ID that no other thread could ever have.
>
> C does not have to do that atomically. In fact it is free to use lots of instructions to build the int value. And some compilers indeed do, the linux kernel folks see this in gcc generated code.
>
> I understand you have to use the new atomics features.
>

Yeah, I didn't have a good analogy so I went with a hypothetical.  The
atomicity would be more useful in that context as it would give
lock-free ID generation, which doesn't work in Python.

ChrisA


More information about the Python-list mailing list