Ruby的Net :: HTTP线程安全?

前端之家收集整理的这篇文章主要介绍了Ruby的Net :: HTTP线程安全?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
Ruby的Net :: HTTP线程安全?

(除了明确说明的version_1_1和version_1_2方法之外)@H_403_3@

解决方法

我不会指望

2008年matz wrote:@H_403_3@

For MRI (1.8.x) and YARV (1.9.x),every C implemented methods are
protected by GIL (Global Interpreter Lock),so that you don’t have to
worry about. But it might depend on each implementation.@H_403_3@

Net :: HTTP在stdlib中,这意味着它没有在C中实现(或者至少没有在C中完全实现).我假设matz在GIL上的说明今天仍然是正确的,这意味着GIL不会放在Net :: HTTP上.因此,我怀疑这将是线程安全的.@H_403_3@

我不幸的是没有在当前版本的Ruby的文档中找到明确的证据,虽然我觉得这也值得一提,从Concurrency in jruby:@H_403_3@

At least these classes [core classes and classes in the stdlib] are
not considered thread-safe,and if you intend to mutate them
concurrently with other operations you will want to introduce locking
(e.g. with Mutex): String,Array,Hash,and any data structures
derived from them.@H_403_3@

通过在Net :: HTTP附近添加锁或使用线程安全的替代方法,我觉得最好安全.@H_403_3@

原文链接:https://www.f2er.com/ruby/266216.html

猜你在找的Ruby相关文章