Yahoo Gmail Google Facebook Delicious Twitter Reddit Stumpleupon Myspace Digg

Search queries

nisc wwwxxx, wwwxxx0cm, should producers of software-based services, such as atms, be held liable for economic injuries suffered when their systems fail?, wwwxxx0cm,, Event 9 IIS log failed to write entry, wwwxxx jeffs, Catastrophic failure Unexpected method call sequence. 0x8000ffff (-2147418113)., ksh lock a file, [unixODBC][Driver Manager]Driver's SQLAllocHandle on SQL_HANDLE_DBC failed



#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