我有一堂课,有一本字典
class OrderBook:
orders = {'Restaurant1': None,
'Restaurant2': None,
'Restaurant3': None,
'Restaurant4': None}
@staticmethod
def addOrder(restaurant_name, orders):
OrderBook.orders[restaurant_name] = orders
我正在运行4个线程(每个餐厅一个线程)来调用方法OrderBook.addOrder
。这是每个线程运行的函数:
def addOrders(restaurant_name):
#creates orders
...
OrderBook.addOrder(restaurant_name, orders)
这样安全吗,还是在致电之前必须使用锁addOrder
?