【发布时间】:2020-04-15 07:19:03
【问题描述】:
假设ray actor 定义如下
@ray.remote
class Buffer:
def __init__(self):
self.memory = np.zeros(10)
def modify_data(self, indices, values):
self.memory[indices] = values
def sample(self, size):
indices = np.random.randint(0, 10, size)
return self.memory[indices]
让其他参与者在没有任何锁的情况下调用Buffer 的方法是线程安全的吗?
【问题讨论】:
-
如果您确保在每个线程的不同对象上执行此操作,那么应该没问题。
-
您好,感谢您的回答。很抱歉,我不明白您所说的
executing this on different objects in each thread是什么意思。供您参考,我没有明确定义任何额外的线程来操作这个对象,这里只涉及到光线演员。 -
我的意思是,如果你在多个线程中处理(即)一些公共文件或资源,那将是一个问题,但如果你正在实例化类在这里,我会说你不会有问题。