I recently came across the GIL present in Python according to which only a single thread can execute at a time and multithreading can not utilize all the cores.
Now in one of my projects, I used multithreading and lots of locks and semaphores So here my question is can I achieve the same thing if I don't use locks and semaphores? i.e if I remove the concurrency logics from my project.
Edit: What I want to know is, whether it's possible to attain same functionality if I remove concurrency logics, I know what is GIL and it prevents threads to use all the cores and only one thread is run at a time.
The Global Interpreter Lock ensures that only one thread is executing byte code at once. That execution could be interrupted at any time.
Consider this simple function which might be intended to atomically store related values to attributes on an instance
x
Here is its disassembly into bytecode
Suppose
x
is not protected by amutex
. Then any thread executingf(x, 1, 2)
can easily be interrupted between storinga
(at10
) and storingb
(at16
). That interrupting thread will now seex
in an inconsistent state.