Does Python have the equivalent of the Java volatile
concept?
In Java there is a keyword volatile
. As far as I know, when we use vola
The keyword "global" is what you are looking for:
import threading
queue = []
l = threading.Lock()
def f():
global queue
l.acquire()
queue.append(1)
l.release()
def g():
print(queue)
threads = [
threading.Thread(target=f),
threading.Thread(target=g)
]
for t in threads:
t.start()
for t in threads:
t.join()