xxxxxxxxxx
import threading
class LockBox:
def __init__(self):
self._lock = threading.Lock()
def open(self):
self._lock.acquire()
def close(self):
self._lock.release()
# Example usage
box = LockBox()
# Thread 1
def thread1():
box.open()
# Perform operations on the lock box
box.close()
# Thread 2
def thread2():
box.open()
# Perform operations on the lock box
box.close()
# Start the threads
threading.Thread(target=thread1).start()
threading.Thread(target=thread2).start()