Yahoo Gmail Google Facebook Delicious Twitter Reddit Stumpleupon Myspace Digg

Search queries

TheboL.wwwxxxxx, WWWXXXAPC , wwwxxn.xsss, wwwxxxapc, WWWXXX.VCBA, wwwxxx vba, wwwxxxdoco, Wwwxxx.APC, wwwxxx CN2, can't locate in @inc (@inc contains



#1: xs module, threads and clone of returned objects

Posted on 2008-01-12 12:27:11 by Andrew Torda

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.

Report this message