A mutex can be used to synchronize access to a resource by multiple read and write threads.
Mutex: An object in a program that serves as a lock, used to negotiate mutual exclusion among threads. from: Wiktionary
Convert the demo program/code in C to Python3. (Not line for line but the concept.)
Demo Program/Code - Mutex Locks in C
What is the difference between Mutex and Semaphores?
Synchronization Primitives (Python3 documentation)
Threading Mutex Lock in Python
Proper use of mutexes in Python
Mutex in Python - Delft Stack
Multithreading in Python | Thread synchronization and Locking
(YouTube)
Python Thread Tutorial For Beginners 5 - Thread Synchronization Using Locks
(YouTube)
Difference between Mutex, Semaphore & Spin Locks