在Ruby 1.9中自动加载线程安全吗? [英] Is autoload thread-safe in Ruby 1.9?

查看:71
本文介绍了在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中自动加载线程安全吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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