Kai
Kai

Reputation: 983

Python Lock internal implementation

Python lock seems to be the most primitive synchronization mechanism used by other synchronization variables.

I wanted to know how a python lock works? Where can I check the source code and implementation of the lock? Also, if multiple threads are waiting on the lock, which thread is woken up during a release?

Upvotes: 1

Views: 851

Answers (1)

Hao Li
Hao Li

Reputation: 1762

How a python lock works?

It is NOT a simple question because of the existence of GIL, have a look at this blog.

Source code

Usually, people use CPython implement. The source code of thread module is here.

How to pickup a thread

Any thread in waiting state has the possibility to be woken up. So you might treat it as a random pickup.

Upvotes: 3

Related Questions