Friday 15 March 2013

multithreading - Perl threads vs. object destructors -


Run this perl program:

  Use strict; Use warnings; Use threads; My $ foo = Foo- & gt; new (); My $ t = thread- & gt; Create (all in {print "threads \ n"}); $ T & gt; joining in (); Package fu; Sub New {Print "Foo-> New \ n"; Blessing {}, 'Foo'; } Sub-destroying {print "Foo-> Delete \ n"; } 1;   

Produces this output:

  Foo-> New in thread Foo- & gt; Delete Foo- & gt; DESTROY   

I think this is happening because Pearl is copying $ FU in the new thread and then when the new thread arrives and when the main thread gets out, it calls the destroyer It seems like bad behavior to me, it is giving me a headache in my very complex, realistic program. Is there no way to get Pearl to do this?

You want to put it in your foo package:

  sub CLONE_SKIP {1}   

(assuming you are not using an ancient Pearl).

But when you start trying to fight that Pearl, when you are copying all of your code and data while creating your new code, you are entering an area where you have threads You have to say that you are using thread to get good advice at that point.

No comments:

Post a Comment