Actors是否可以使用线程局部变量进行答复而导致错误? [英] Can Actors reply, which uses a thread local variable, cause a bug?

查看:73
本文介绍了Actors是否可以使用线程局部变量进行答复而导致错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到,演员 回复调用 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆