What might happen if I use a boolean value to control a cycle of a thread if I don't lock it before checking its value. Can an exception be raised?
Notice that is not a problem if my cycle run once more, but if possible I'd like to avoid the cost of locking the resource
# self is the same object in the 2 functions
def __init__(self):
self.status=True
# thread 1
def stop(self):
# Lock acquired to avoid concurrent writes
self.lock.acquire()
self.status=False
self.lock.release()
# thread 2
def thread_func(self):
while self.status:
# Do stuff
# Not important if it does a cycle more after status is set to false