Bookmarks

Yahoo Gmail Google Facebook Delicious Twitter Reddit Stumpleupon Myspace Digg

Search queries

www.webdp.net, 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, sed: -e expression #1, char 1: unterminated address regex, procmail + change subject, w2ksp4.exe download, /proc/kallsyms format

Links

XODOX
Impressum

#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