I have 2 threads running in the same function. I want to edit the data structures later in the code, but I want to make sure that both the threads have read the data and any future changes in the dict_list and ans_list will not be read by these threads. I was thinking of making use of commands such as wait() and notify() just before mutex.acquire() but since both the threads are using the same function, the second thread will have to wait for a notify that will never come.
How can I approach this problem?
def foo():
//Reading the dict_list and ans_list here
mutex.acquire()
ans_list[room_no-1] = ""
dict_list[room_no-1].clear()
mutex.release()