Ruby的Net :: HTTP线程安全?

Ruby的Net :: HTTP线程安全?

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

解决方法

我不会指望

2008年matz wrote

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.

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

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

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.

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

相关文章

validates:conclusion,:presence=>true,:inclusion=>{...
一、redis集群搭建redis3.0以前,提供了Sentinel工具来监控各...
分享一下我老师大神的人工智能教程。零基础!通俗易懂!风趣...
上一篇博文 ruby传参之引用类型 里边定义了一个方法名 mo...
一编程与编程语言 什么是编程语言? 能够被计算机所识别的表...
Ruby类和对象Ruby是一种完美的面向对象编程语言。面向对象编...