Re: threads, XSUB allocated memory, destructors, destruction
- From: xhoster@xxxxxxxxx
- Date: 10 Oct 2005 16:36:23 GMT
Andrew Torda <please@xxxxxxxxxxx> wrote:
> Greetings from the original poster
> > Thanks for taking the time to provide that example. That about wraps it
> > up for me ..... wonder how the op is getting on with this :-)
>
> I can tell you... Not very happy.
> Using CLONE_SKIP() does what it should. It stops you being
> destroy()ed. Unfortunately, "man perlmod" says your objects
> "will be copied as unblessed, undef values" and "if the
> child thread needs to make use of the objects, then a more
> sophisticated approach is needed.
Another possible way to prevent the children threads from trying to
free the data is to have the threads bail out with a POSIX::_exit.
I do this in forked processes all the time (where the goal is to prevent
the costs of cleaning up, which can be very great for large amounts of
data, especially with cow), but don't know how it will work in threads.
> OK.
> Maybe I should write my own CLONE(), although this is a bad
> idea. Perldoc Threads::shared says that "Currently CLONE is
> called with no parameters other than the invocant package
> name". This means you can't get to the address you need to do the
> copying.
You can, but you need to store that address (those addresses) somewhere
other than in the objects themselves (or you need to store the objects
themselves somewhere in the package).
> It is a catastrophically ugly approach to a large amount
> of data which should be shared since it is passed to threads for
> use in some calculations.
Exactly what kind of sharing are you doing? Is most the sharing read
only or does each thread need to be able to write such that the other
threads can see the changes?
If only the "master" thread need to write to this large amount of data,
and if you are using a unix-like system, then you could try forking
rather than threads. Perl may not know how to clone XSUB data, but the
kernel does know how to. And because of cow (copy on write), forked data
can live in the same RAM as the original until it starts getting changed.
>
> We are dealing with arrays of blessed objects. They should
> be shared between threads, but then one hits the problem
> that ""bless" is not supported on shared references. In other
> words, if one has a reference to a 2D array of blessed objects
> and says p $$coords[0][0], you get something like
> MyPtr=SCALAR(0x85efe8c). If you then mark it as shared,
> "share $coords", and try the print statement, you are bluntly
> told, "Invalid value for shared scalar at ...".
You should not get that from a print statement. That error occurs either
when you assign to a shared variable, or when you share a variable. Not
when you read from a variable.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
.
- References:
- Re: threads, XSUB allocated memory, destructors, destruction
- From: Sisyphus
- Re: threads, XSUB allocated memory, destructors, destruction
- From: Sisyphus
- Re: threads, XSUB allocated memory, destructors, destruction
- From: xhoster
- Re: threads, XSUB allocated memory, destructors, destruction
- From: Tassilo v. Parseval
- Re: threads, XSUB allocated memory, destructors, destruction
- From: Sisyphus
- Re: threads, XSUB allocated memory, destructors, destruction
- From: Tassilo v. Parseval
- Re: threads, XSUB allocated memory, destructors, destruction
- From: Sisyphus
- Re: threads, XSUB allocated memory, destructors, destruction
- From: Tassilo v. Parseval
- Re: threads, XSUB allocated memory, destructors, destruction
- From: Sisyphus
- Re: threads, XSUB allocated memory, destructors, destruction
- From: Andrew Torda
- Re: threads, XSUB allocated memory, destructors, destruction
- Prev by Date: FAQ 8.12 How do I start a process in the background?
- Next by Date: Re: parsing postfix bounce back emails from log
- Previous by thread: Re: threads, XSUB allocated memory, destructors, destruction
- Next by thread: Re: threads, XSUB allocated memory, destructors, destruction
- Index(es):
Relevant Pages
|