IronRuby ScriptSource.Execute 线程安全吗?
我们通过托管 IronRuby 引擎实现表达式评估器。您可以在此处查看评估器的简化版本。
现在,我们试图通过在多个线程中执行表达式来从 IronRuby 获得更高的性能(我们得到了它)。有一个问题困扰着我们 - Execute 方法线程安全吗?
We are implemented expression evaluator via hosting IronRuby engine. Simplified version of evaluator you can see here.
Now we are trying to get more performance from IronRuby via executing expressions in many threads (and we got it). One question bothers us - is Execute method thread safe?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
ScriptRuntime
、ScriptEngine
和ScriptScope
都是线程安全的,设计用于在线程之间使用。具体来说,ScriptScope
使用线程安全的数据存储,因此ScriptScope
可以在线程之间共享。如果您提供自己的作用域来执行脚本,则需要确保该作用域的数据存储是线程安全的。此外,当改变 ScriptScope 中的数据时,线程安全是通过锁定来确保的,因此请注意,许多不同的线程改变共享的 ScriptScope 会降低性能。从 ScriptScope 读取数据不会锁定。
ScriptRuntime
,ScriptEngine
, andScriptScope
are all thread safe, designed to be used between threads. Specifically,ScriptScope
uses a thread-safe data-store, soScriptScope
can be shared between threads.If you provide your own scope for scripts to execute against, you will need to ensure that scope's data store is thread-safe. Also, when mutating data in a
ScriptScope
, thread-safety is ensured by locking, so be aware that many different threads mutating a sharedScriptScope
will degrade performance. Reading data from a ScriptScope does not lock.