in reply to CLONE/DESTROY want work at all??

Every time you clone a thread, it walks through the %MY_CXT structure and increments counts on everything in there. When a thread exits it gets DESTROYed only once - in the thread that was running. Therefore every thread gets CLONED many times, and DESTROYed only once. This adds up to many more CLONEs than DESTROYs.

Replies are listed 'Best First'.
Re^2: CLONE/DESTROY want work at all??
by spacepille (Acolyte) on May 21, 2009 at 20:54 UTC
    Since CLONE deals with the package and DESTROY deals with the object, it's not possible to get a module threadsafe, when it uses shared stuff?
      What makes you think it is not threadsafe?

      It is doing what you are asking for. You have a global structure. As each thread spawns, it walks the whole global structure, while locking appropriately. If you don't want it to walk the whole global structure don't.

      If that is not what you meant to ask for, then don't ask for that.

      In general with threads I strongly recommend having the simplest possible design. And then thinking through consequences very, very carefully. Because things will interact in unexpected ways. And when you've got multiple threads (or processes) around whose interactions with you are all mixed up, you can easily get very, very confused.

        My intention to ask was.. How can i use shared things like file handles in XS modules, when CLONE/DESTROY don't provide a clean way for destruction in the case that i showed in the example above? I wrote some XS modules to make Perl faster and smaller. I'm using this modules in serveral programs, but it doesn't work right. MY_CXT makes no sense when i have a file handle or socket handle in it, which must be closed. It seems that Perl doesn't work right with threads. I decided to go away from it. Bummer!