in reply to code executed at end of a thread

.... any other ideas?.... yes..... a thread needs to return or go to end of it's code block before it can finish..... so i have retreated into the brute force habit of using a GOTO as a way of terminating a thread, where the GOTO label sends execution to a few lines preceeding the threads actual return...... you can do your thread specific cleanup there....but as always....i may be missing the secret design you have :-)

...see Reusable threads demo and look at the end of the thread code block..... and it would be good to follow TGI's advice to use cleanly labeled nested loops instead of GOTO's ;-)

....i'm an old dog and reserve the right to use a goto every now and then


I'm not really a human, but I play one on earth.
Old Perl Programmer Haiku

Replies are listed 'Best First'.
Re^2: code executed at end of a thread
by dk (Chaplain) on Dec 04, 2009 at 14:59 UTC
    That's so far my best guess too - except that my design is that I'm writing a generic library, and don't have a control over what threads do, that's up to the programmers. I'd hate to impose an extra requirement, like "hey use my lib but also use a goto" (I personally don't mind goto at all, and use them too), but you get my drift...

    I thought rather that I missed some obscure language feature, and am trying to reinvent a wheel.

      .... well then, use the nested labeled loops, as i suggested..... that code is just a simple example to illustrate exacting thread control..... running threads on manual so to speak, rather than requireing a thread helper library like a queue......and goto's are such a clean hack, that everyone should have it in their toolkits, even if the bossman dosn't like them :-)

      ....you can start up threads and pass perl code strings to them, thru shared variables, and have them eval'd in the thread.....but then the ugliness of an exit call taking down the whole house of cards raises it's head..... i don't know what you are doing, but threads may not be what you are looking for....unless you are on win32..... bwahaha.... then i can't help

      ....but you may have a bigger design problem with module safety..... hows that for b*llsh*t ;-)


      I'm not really a human, but I play one on earth.
      Old Perl Programmer Haiku
        "unless i'm on 32"... year right :) I'm using threads to emulate a proper popen() on win32 that returns a handle that I can use in select() . Other than this, the advice above with END inside eval actually works for me just fine.

        thanks for a brainstorm!