Click here to get back home

threads, XSUB allocated memory, destructors, destruction

 HomeNewsGroups | Search | About
 comp.lang.perl.modules    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
threads, XSUB allocated memory, destructors, destruction Andrew Torda 09-30-2005
Posted by Andrew Torda on September 30, 2005, 6:31 pm
Please log in for more thread options


I have a perl module built out of XSUBs.
The functions malloc() space, build structures and return
pointers to perl. Perl calls their destructor routines with no
problems. The C structures go back to the perl interpreter, as
T_PTROBJ things, specified in a typemap file.

Now, if I use threads, I
make lots of new data
break my arrays into 2 pieces
threads->new( myfunc, @array_to_read_from);
threads->new( myfunc, @array_to_read_from);
thread[0]->join
thread[1]->join

Unfortunately, at the join() stage, each thread decides to
cleanup, and call the destructors for my @array_to_read_from.
Obviously free() gets called multiple times, terrible things
happen to the heap and everything dies.

What should I be doing in my XSUBs when I create objects (really
just pointers to malloc()'d space) to ask perl not to do this ?
I am sure I am missing something obvious, but I cannot find it in
perlxs or perlxstut man pages.
Many thanks for any advice.



Similar ThreadsPosted
ImageMagick and threads October 12, 2004, 1:44 pm
perl and threads July 18, 2006, 9:20 am
LWP::UserAgent + HTTPS + threads ==> segmentation fault November 11, 2004, 9:57 pm
xs module, threads and clone of returned objects January 12, 2008, 6:27 am
Out of Memory error September 12, 2004, 11:51 pm
CPAN shell says "Out of memory!" December 30, 2005, 5:15 pm
Shared memory for data structures September 8, 2004, 11:13 am
Leaking memory in Perl XS Module November 8, 2004, 10:40 am
Memory Leak in Math::Pari December 16, 2004, 6:21 am
Thread::Semaphore consumes memory January 7, 2005, 11:05 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap