加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Ruby的Net :: HTTP线程安全?

发布时间:2020-12-16 22:16:28 所属栏目:百科 来源:网络整理
导读: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
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附近添加锁或使用线程安全的替代方法,我觉得最好安全.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读