I wanted to build an awesome place for people to discuss module specific issues, but I don't have any more time for this, and there are much better places to discuss Perl-related issues. I'd recommend asking your question on Stack Overflow or on Perl Monks.
If you are looking for a Perl tutorial or Perl-related news, I hope these links will serve you well.
Posted on 2008-04-15 11:25:03-07 by kende
Strange Error: PmmREFCNT_dec: REFCNT decremented below 0!
Hi Guys, I am using threads-1.69 with threads-shared-1.18 in my Perl program on a Linux machine. I have 3 modules x.pm, y.pm and common.pm. Both x.pm and y.pm uses the threads module therefore 'use threads;' is in common.pm. x.pm works fine but y.pm has give me some strange error message when I am trying to join the joinable threads. I read the "Making your module threadsafe" but It was not totally clear. Please give me some help or hint.

Error:
...
+Limit Reached
- 1 1
PmmREFCNT_dec: REFCNT decremented below 0! during global destruction.
...
Segmentation fault (core dumped)
...


Example code:
for(my $i=0; $i < scalar(@Hosts); $i++) { if(getThreadsNum() >= config::THREAD_NUM) { print("\n\n+Limit Reached \n"); while(getThreadsNum() >= config::THREAD_NUM) { foreach my $threadJoin (threads->list(threads::joinable)) { my @result = $threadJoin->join(); print("Join: $result[0] $result[1] \n"); } } } push @ThreadListValidate, threads->new(\&test, $i); threads->yield(); } ... etc
Gabor
Direct Responses: 7671 | Write a response
Posted on 2008-04-15 11:50:07-07 by kende in response to 7669
Re: Strange Error: PmmREFCNT_dec: REFCNT decremented below 0!
... a little update

I started playing with gdb and it looks like that LibXML cause the problem
+Limit Reached
- 1 1
PmmREFCNT_dec: REFCNT decremented below 0! during global destruction.
PmmREFCNT_dec: REFCNT decremented below 0! during global destruction.
PmmREFCNT_dec: REFCNT decremented below 0! during global destruction.
PmmREFCNT_dec: REFCNT decremented below 0! during global destruction.

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread -161607552 (LWP 2051)]
0x00454fc2 in PmmREFCNT_dec () from
//ms/dist/perl5/PROJ/XML-LibXML/1.58-2.6.22-5.8/lib/perl5/auto/XML/LibXML/LibXML.so
(gdb)
Direct Responses: 7672 | Write a response
Posted on 2008-04-15 12:40:36-07 by jdhedden in response to 7671
Re: Strange Error: PmmREFCNT_dec: REFCNT decremented below 0!
XML::LibXML is an XS-code based module, and is most likely not written to be thread-safe. You should file a bug against that module.

As a workaround, you could try following the advise in the Using non-thread-safe modules section of the threads POD.
Direct Responses: 7674 | Write a response
Posted on 2008-04-15 14:15:54-07 by ssinyagin in response to 7672
Re: Strange Error: PmmREFCNT_dec: REFCNT decremented below 0!
it's actually libxml2 that is not thread-safe. There's no workaround. I had to put semaphores around the LibXML calls, then it worked: See line 509 in http://torrus.cvs.sourceforge.net/torrus/src/bin/devdiscover.in?revision=1.15&view=markup
Direct Responses: 7676 | Write a response
Posted on 2008-04-15 15:37:10-07 by kende in response to 7674
Re: Strange Error: PmmREFCNT_dec: REFCNT decremented below 0!
I was able to solve the problem with using a newer version of XML::LibXML (1.66-2.6.31)
Direct Responses: Write a response