在Ruby 1.9中自动加载线程安全吗?

编程入门 行业动态 更新时间:2024-10-24 22:27:44
本文介绍了在Ruby 1.9中自动加载线程安全吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在我看来,自此著名线程以来,Ruby社区一直对自动加载感到有些恐惧. ,出于线程安全的考虑,不建议使用它.

It seems to me that the Ruby community has been freaking out a little about autoload since this famous thread, discouraging its use for thread safety reasons.

有人知道这在Ruby 1.9.1或1.9.2中不再是问题吗?我已经看到了一些有关在互斥对象中包装要求的讨论,但是1.9更改日志(或至少与我能够找到的一样)似乎没有解决这个特定问题.我想知道我是否可以合理地开始在仅1.9版本的库中自动加载而不会遇到任何麻烦.

Does anyone know if this is no longer an issue in Ruby 1.9.1 or 1.9.2? I've seen a bit of talk about wrapping requires in mutexes and such, but the 1.9 changelogs (or at least as much as I've been able to find) don't seem to address this particular question. I'd like to know if I can reasonably start autoloading in 1.9-only libraries without any reasonable grief.

在此先感谢您提供任何见解.

Thanks in advance for any insights.

推荐答案

我不了解一般情况,但是该线程的repro示例在1.9.1中不会中断:

I don't know about the general case, but repro example from that thread doesn't break in 1.9.1:

autoloaded.rb:

autoloaded.rb:

sleep 1 Bar::Foo = 1

autoloader.rb:

autoloader.rb:

module Bar autoload :Foo, 'autoloaded.rb' end t1 = Thread.new { Bar::Foo } t2 = Thread.new { Bar::Foo } t1.join; t2.join

更多推荐

在Ruby 1.9中自动加载线程安全吗?

本文发布于:2023-11-25 18:59:35,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1630955.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:线程   自动加载   Ruby

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!