Perl-如何使特定于单个线程的库 [英] Perl - How to make a library specific to individual threads

查看:79
本文介绍了Perl-如何使特定于单个线程的库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用perl编写多线程脚本.我在其中使用库Net::Netconf::Manager,而库又使用Net::SSH2.当同时共享处理"时,此Net :: SSH2(libssh2)似乎不是线程安全的.

I am writing a multi threaded script in perl. In which I am using a library Net::Netconf::Manager which inturn uses Net::SSH2. This Net::SSH2(libssh2) doesn't seem to be thread safe when 'shared handles' simulataneously.

我在 libssh2网站上引用

线程安全:只是不要同时共享句柄

  1. 我不确定这个共享句柄"是什么意思.我也想知道如何不共享句柄".

当我运行脚本时,偶尔会看到错误跟踪,其中包含backtrace和表示*** glibc detected *** perl: double free or corruption (out): 0x00007f0320012d70 ***错误的内存映射.该错误是由于Net :: SSh2库的线程安全性所致.

When I run my script, occasionally i see error trace with backtrace and memory map denoting *** glibc detected *** perl: double free or corruption (out): 0x00007f0320012d70 *** error. This error is because of the thread safeness of the Net::SSh2 library.

  1. 如何使此Net :: Netconf :: Manager可用于每个线程,而不是用'use'全局声明它.我希望所有线程都可以独立于其他线程而独立访问该库.
  1. How to make this Net::Netconf::Manager available to every thread instead of having it declared globally with 'use' . I want all the threads to have their own access to this library independent of other threads.

请让我知道您的看法.

推荐答案

我是Net::SSH2的当前维护者.

我从来没有追求过该模块的线程安全性,但对其代码进行了浅浅的检查,发现可能是双重释放错误是由Net::SSH2对象的Perl端在创建线程时克隆而C端引起的不是.这样会导致libssh2对象被破坏并释放两次,从而导致程序崩溃.

I have never went after thread safeness for that module but a shallow inspection of its code, shows that probably, that double free error is caused by the Perl side of the Net::SSH2 objects being cloned on thread creation while the C side is not. That results in libssh2 objects being destroyed and released twice which results in the program crashing.

因此,如果要在多线程应用程序中使用Net::SSH2,则应确保不要从存在该模块对象的线程中创建线程.

So, if you want to use Net::SSH2 in a multithread application you should ensure that threads are never created from threads where objects of this module exist.

即使在模块上也可能存在其他错误.

Even then there may be other bugs lurking on the module.

显然,正确的做法是修复模块.如果您想自己做,我会尽力帮助您.请与我联系,以便我们可以首先讨论细节...否则,既然您已经引起了我的注意,也许在某个时候我会自己修复...但是这不会一夜之间发生.

Obviously the right thing to do would be to fix the module. If you want to do it yourself, I would try to help you. Just get in touch with me so that we could discuss the details first... Otherwise, now that you have brought that issue to my attention, well, probably at some point I will fix it myself... but this is not going to happen overnight.

这篇关于Perl-如何使特定于单个线程的库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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