Perl:特殊变量线程安全吗?
我正在阅读一些有关 $@ 全局变量的问题,以及如何在处理它之前由于成功的评估将其清除干净而对其进行破坏。
但是,如果它被并发线程中发生的错误所破坏怎么办?新的线程包表示默认情况下不共享内容,这意味着它是少数几种能够生成“$a = $a;”的主流语言之一默认情况下是确定性的(并且认为人们说 C# 和 Java 在大型项目中比 Perl 更好)。但我不确定特殊的全局变量。
我的直觉告诉我它们就像任何其他变量一样,因此它们不会被共享。我大脑的本能告诉我“让我们与 Stackoverflow 上的向导核实一下”。
我检查了 Perldoc 上的线程教程,它涵盖了共享部分中的普通变量,但随后似乎没有涵盖特殊变量。
即使我没有首先本地化它们,我是否可以使用特殊变量而不会有它们被其他线程破坏的风险?例如,我可以从 $@ 中提取一个值而不用担心并行线程中发生的错误吗?
I was reading some questions regarding the $@ global variable and how it can be clobbered before it's even handled due to successful evals wiping it clean.
But what if it gets clobbered by an error occurring in a concurrent thread? The new threads package says stuff isn't shared by default, which means it's one of the few mainstream languages that makes '$a = $a;' deterministic by default (and to think that people say C# and Java are better than Perl in large projects). But I'm not sure about special global variables.
My gut's instinct says they're just like any other variable, thus they won't be shared. My brain's instinct says 'let's check with the wizards on Stackoverflow'.
I checked the threading tutorial on Perldoc, and it covers normal variables in the sharing section, but then seems to move on without covering special variables.
Can I use the special variables without risk of them being clobbered by other threads, even if I don't localize them first? E.g. can I pull a value out of $@ without worrying about errors occurring in parallel threads?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你的勇气是对的,它们不被分享!
your guts are right, they are not shared!