Thank you for your reply.
Why do you need to handle the destruction of these?
Because i wanted to make Perl faster, smaller and even better. For example i wrote the Socket::Class module. It handles IPv6, includes SSL and it uses the C socket API instead of the PerlIO layer. Since MY_CXT clones with every thread, i'm using a global structure and a thread mutex to hold the data for Socket::Class. It works fine, is fast and saves memory. But in this case i need the correct time to destruct the shared data structure. I also started writing some new database drivers, which require similar mechanism.

The shared and global %MY_CXT hash was not a good example. But i used it to prevent from answering "take a look to MY_CXT mechanism". Because i did already many times :)

I believe i also did already understand what CLONE does. It's called once a new thread is created for each class or inherited class. Please see the following from perlmod/perldoc:

If you want to CLONE all objects you will need to keep track of them per package.

Because of this i'm incrementing the reference counts every time CLONE is called.

Your example works as expected as long as the sub threads close before the main thread creates new ones.
Try it out. Set the sleep time in the sub threads to a higher value then the main thread sleep time. The reference counts become different. I think it starts at the point where the main variables are overwritten. ($obj1 = Class->new())
This is the problem that i have :)


In reply to Re^8: CLONE/DESTROY want work at all?? by spacepille
in thread CLONE/DESTROY want work at all?? by spacepille

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.