in reply to Re^4: Parallel Modules ?
in thread Parallel Modules ?

Your problem is this line:

my $thr = threads->create(Better::saveBetter, @ParamList); ##.......................^^^^^^^^^^^^^^^^^^

The indicated part (Better::saveBetter) is invoking that subroutine and then passing the result to threads->create() as the first argument.

Replace that line with:

my $thr = threads->create( \&Better::saveBetter, @ParamList );

And your sample will work.

Or rather it will once you correct the typo:

my ($sbn, $cost, $ur) = @_; #..................^^^ print "url: $url\n"; #..............^^^^

Which would have been caught if you had use strict & use warnings in your module.

And would be far more obvious visually if you formatted your code with spaces in the right places:

my( $sbn, $cost, $ur ) = @_;

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

The start of some sanity?

Replies are listed 'Best First'.
Re^6: Parallel Modules ?
by Gary Yang (Acolyte) on Nov 29, 2011 at 23:55 UTC

    Thanks a lot for your help. However, I got "Segmentation fault" with my real code. Then, I used "perl -d" and "s" command to step through all the sub routines. Looks like the failure is related to LibXML. Any idea how to make it work?

    ......

    DB<1> s
    XML::LibXML::Node::CLONE_SKIP(/usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi/XML/LibXML.pm:1249): 1249: return $XML::LibXML::__threads_shared ? 0 : 1;

    DB<1> s
    XML::LibXML::XPathContext::CLONE_SKIP(/usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi/XML/LibXML/XPathContext.pm:25): 25: sub CLONE_SKIP { 1 }

    DB<1> s
    XML::LibXML::CLONE_SKIP(/usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi/XML/LibXML.pm:414): 414: return $XML::LibXML::__threads_shared ? 0 : 1;

    DB<1> s
    XML::LibXML::SAX::CLONE_SKIP(/usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi/XML/LibXML/SAX.pm:26): 26: return $XML::LibXML::__threads_shared ? 0 : 1;

    DB<1> s
    Segmentation fault

    I use the modules below.

    use strict; use warnings; use Scalar::Util 'reftype'; use encoding "utf8"; use Data::Dumper; use CGI qw(:standard Vars); use LWP::UserAgent; use XML::Simple; use threads;

      I'm guessing that you are trying to use a single instance of some object across multiple threads.

      It'd be a hell of a lot easier to help you if you posted the actual code.


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

      The start of some sanity?

        I found the root cause of the problem. use encoding "utf8" caused the segmentation fault. I removed it. Problem is gone. However, I got "corrupted double-linked list" at run time. It does not always happen. Sometimes the program works fine. Sometimes, I got "corrupted double-linked list". Program died when it happened. Below are the messages. I have no clue what causes it. Any idea?

        *** glibc detected *** /usr/bin/perl: corrupted double-linked list: 0x +000000000bbec430 *** ======= Backtrace: ========= /lib64/libc.so.6[0x366cc70583] /lib64/libc.so.6[0x366cc7222c] /lib64/libc.so.6(cfree+0x4b)[0x366cc7273b] /usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/CORE/libperl.so(perl_ +destruct+0xffa)[0x366dc3966a] /usr/bin/perl(main+0xb3)[0x401773] /lib64/libc.so.6(__libc_start_main+0xf4)[0x366cc1d994] /usr/bin/perl[0x401609] ======= Memory map: ======== 00400000-00403000 r-xp 00000000 08:03 75519 + /usr/bin/perl 00602000-00604000 rw-p 00002000 08:03 75519 + /usr/bin/perl 0a327000-0c5c3000 rw-p 0a327000 00:00 0 + [heap] 422bd000-422be000 ---p 422bd000 00:00 0 422be000-42cbe000 rw-p 422be000 00:00 0 42cbe000-42cbf000 ---p 42cbe000 00:00 0 42cbf000-436bf000 rw-p 42cbf000 00:00 0 436bf000-436c0000 ---p 436bf000 00:00 0 436c0000-440c0000 rw-p 436c0000 00:00 0 3513c00000-3513d38000 r-xp 00000000 08:03 2523842 + /usr/lib/libxml2.so.2.7.8 3513d38000-3513f37000 ---p 00138000 08:03 2523842 + /usr/lib/libxml2.so.2.7.8 3513f37000-3513f41000 rw-p 00137000 08:03 2523842 + /usr/lib/libxml2.so.2.7.8 3513f41000-3513f42000 rw-p 3513f41000 00:00 0 366c800000-366c81c000 r-xp 00000000 08:03 1638708 + /lib64/ld-2.5.so 366ca1b000-366ca1c000 r--p 0001b000 08:03 1638708 + /lib64/ld-2.5.so 366ca1c000-366ca1d000 rw-p 0001c000 08:03 1638708 + /lib64/ld-2.5.so 366cc00000-366cd4d000 r-xp 00000000 08:03 1638709 + /lib64/libc-2.5.so 366cd4d000-366cf4d000 ---p 0014d000 08:03 1638709 + /lib64/libc-2.5.so 366cf4d000-366cf51000 r--p 0014d000 08:03 1638709 + /lib64/libc-2.5.so 366cf51000-366cf52000 rw-p 00151000 08:03 1638709 + /lib64/libc-2.5.so 366cf52000-366cf57000 rw-p 366cf52000 00:00 0 366d000000-366d082000 r-xp 00000000 08:03 1638712 + /lib64/libm-2.5.so 366d082000-366d281000 ---p 00082000 08:03 1638712 + /lib64/libm-2.5.so 366d281000-366d282000 r--p 00081000 08:03 1638712 + /lib64/libm-2.5.so 366d282000-366d283000 rw-p 00082000 08:03 1638712 + /lib64/libm-2.5.so 366d400000-366d402000 r-xp 00000000 08:03 1638608 + /lib64/libdl-2.5.so 366d402000-366d602000 ---p 00002000 08:03 1638608 + /lib64/libdl-2.5.so 366d602000-366d603000 r--p 00002000 08:03 1638608 + /lib64/libdl-2.5.so 366d603000-366d604000 rw-p 00003000 08:03 1638608 + /lib64/libdl-2.5.so 366d800000-366d816000 r-xp 00000000 08:03 1638711 + /lib64/libpthread-2.5.so 366d816000-366da15000 ---p 00016000 08:03 1638711 + /lib64/libpthread-2.5.so 366da15000-366da16000 r--p 00015000 08:03 1638711 + /lib64/libpthread-2.5.so 366da16000-366da17000 rw-p 00016000 08:03 1638711 + /lib64/libpthread-2.5.so 366da17000-366da1b000 rw-p 366da17000 00:00 0 366dc00000-366dd2b000 r-xp 00000000 08:03 202553 + /usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/CORE/libperl.so 366dd2b000-366df2b000 ---p 0012b000 08:03 202553 + /usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/CORE/libperl.so 366df2b000-366df34000 rw-p 0012b000 08:03 202553 + /usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/CORE/libperl.so 366df34000-366df36000 rw-p 366df34000 00:00 0 3670000000-367000d000 r-xp 00000000 08:03 1638714 + /lib64/libgcc_s-4.1.2-20080825.so.1 367000d000-367020d000 ---p 0000d000 08:03 1638714 + /lib64/libgcc_s-4.1.2-20080825.so.1 367020d000-367020e000 rw-p 0000d000 08:03 1638714 + /lib64/libgcc_s-4.1.2-20080825.so.1 3673800000-3673815000 r-xp 00000000 08:03 1638453 + /lib64/libnsl-2.5.so 3673815000-3673a14000 ---p 00015000 08:03 1638453 + /lib64/libnsl-2.5.so 3673a14000-3673a15000 r--p 0Abort


        Here is my system info:
        uname -a
        Linux 2.6.18-164.el5 #1 SMP Tue Aug 18 15:51:48 EDT 2009 x86_64 x86_64 x86_64 GNU/Linux
        perl -v
        This is perl, v5.8.8 built for x86_64-linux-thread-multi
        Copyright 1987-2006, Larry Wall
        Modules I used

        use strict; use warnings; use threads; use Scalar::Util 'reftype'; use Data::Dumper; use CGI qw(:standard Vars); use LWP::UserAgent; use XML::Simple;