Click here to get back home

xs module, threads and clone of returned objects

 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
xs module, threads and clone of returned objects Andrew Torda 01-12-2008
Posted by Andrew Torda on January 12, 2008, 6:27 am
Please log in for more thread options
I have an xs module which allocates lots of things, each of which
has malloc()'d space. If I want to work with threads, I do as the
manuals say and, for each type of thing, provide a CLONE()
function. This means I have to have my own reference counting
whenever I create anything. CLONE just increments the reference
count and the _DESTROY() function knows not to free() my memory
until it is the last reference. This all seems to work. Now, I
have a terrible problem:

sub parent () {
threads->new( child1, ...);
and the child function does
sub child ( ...)
... do work ...
... make a thing with malloc()d memory
return (thing)
When the child thread is created, thing_CLONE() is called.
When the child finishes, he returns a thing, then cleans up,
including calling thing_DESTROY(). The memory is wiped out and
the parent gets a pointer to free()d memory.

I cannot see how to fix this. The problem is that perl does not
realise that a return value is also a valid
reference. thing_CLONE() does not seem to be called.

CLONE_SKIP is also of no help.
Grateful for any advice.

Similar ThreadsPosted
xs module, threads and clone() - how does clone work ? January 8, 2008, 3:42 am
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
threads, XSUB allocated memory, destructors, destruction September 30, 2005, 6:31 pm
How to get an OLE array of objects? August 17, 2006, 6:33 pm
calling methods on deserialized objects August 25, 2006, 4:32 pm
compare MSXML objects (nodes) February 28, 2007, 2:49 am
Bit::Vector objects serialized with Storable not working September 13, 2004, 3:15 am
SOAP::Lite creating remote objects March 29, 2006, 9:51 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap