Actors是否可以使用线程局部变量进行答复而导致错误? [英] Can Actors reply, which uses a thread local variable, cause a bug?
问题描述
我注意到,演员
回复调用 ReplyReactor
reply 方法>类型(请参阅私有方法 rawSelf
)。此 reply
方法向 senders.head
发送一条消息,其中 senders
是发件人列表(请参见源)。
I noticed that Actor
reply invokes the reply
method of a thread local variable of ReplyReactor
type (see private methodrawSelf
). This reply
method sends a message to the senders.head
, where the senders
is a list of senders (see the source).
现在,我想知道它是否会导致错误。如果两个参与者与一个本地线程 ReplyReactor
实例共享一个线程怎么办?有一种情况,当一个参与者回复一个错误的发件人吗?
Now I wonder if it may cause a bug. What if two actors share one thread with a thread local ReplyReactor
instance ? Is there a scenario, when one of the actors replies to a wrong sender ?
推荐答案
参与者确实共享线程,但是他们不能打断了。它们将一直运行到下一个反应
或循环
结束时,此时它们不能回复
,然后再执行反应
或接收
。
Actors do share threads, but they cannot be interrupted. They'll run until the next react
or end of loop
, at which point they cannot reply
anymore, before doing another react
or receive
.
这篇关于Actors是否可以使用线程局部变量进行答复而导致错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!