Re: about SFTP and Thread dependency

[email protected] ("Jenda Krynicky")
Newsgroups perl.beginners
Message-ID <[email protected]>
From: "Rajnikant" <[email protected]>
> I was trying to use SFTP in multithreaded application. I observed many
> segmentation faults there.
> Following is the code snipet:
>  
> use threads;
> use Net::SFTP;
>  
> my $thrId = 1;
> my $thread = threads->new (\&ftpThreadEntry,$thrId);
> $thrId = 2;
> print("Creating second thread \n");
> my $thread1 = threads->new (\&ftpThreadEntry,$thrId);
>  
> sub ftpThreadEntry()
> {
>    my $ThrId = shift;
>    print (" Thread $ThrId in ftpThreadEntry func\n");
> }
>  
> $thread->join();
> $thread1->join();
> 
> My Observations :
>  
> 1. If we comment out 'use Net::SFTP' then this code runs fine without
> segmentation fault.
> 2. If we uncomment 'use Net::SFTP', it gives segmentation fault :(.
>  
> Can anyone experienced such situation? Is there any dependency in these
> modules or 
> I'm doing it wrong?

The module is most likely not threadsafe ... or uses something that 
is not. Try to load it only in one thread and only after the other 
thread was created.

Keep in mind that you'll have to use either
	require Net::SFTP;
or
	eval "use Net::SFTP";
otherwise the module would still be loaded too soon.

Jenda
===== [email protected] === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
	-- Terry Pratchett in Sourcery
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.