in reply to Re^2: In a multithreading Perl Code How to Exit one thread while outher thread keeps running ?
in thread In a multithreading Perl Code How to Exit one thread while outher thread keeps running ?

So you mean you want to keep part of your program running yet signal success to the calling program? That's not possible with threads. You will need to daemonize your program so it runs in the background.

  • Comment on Re^3: In a multithreading Perl Code How to Exit one thread while outher thread keeps running ?

Replies are listed 'Best First'.
Re^4: In a multithreading Perl Code How to Exit one thread while outher thread keeps running ?
by JavaFan (Canon) on Jul 06, 2009 at 13:51 UTC
    So you mean you want to keep part of your program running yet signal success to the calling program? That's not possible with threads.
    Considering that variables can be shared in threads (which is about the only reason to use threads - if you don't need to communicate between threads, you might as well fork), returning status should be easy. Note that most implementation, sharing variables is the default in threads, but Perl does the opposite, but you can mark variables as shared.

      I've interpreted the problem as returning an exit status of 0 to the calling process, which is hard as long as you've got threads running, as a process consists of its threads, at least under Windows. I don't know if POSIX is different - at least POSIX threads share the same ID-space as processes, so the main thread might exit there and still leave other threads running, but I doubt that.

        The POSIX model is that when the primary thread ("main") ends, so do all the others. Perl follows this model.
        In theory the Windows model should allow other threads to complete without the primary thread, but the C RTL is not implemented in this way: exiting the primary thread calls ExitProcess().
        Fork ..... Yes this is what I am looking for. I got the solution. Thanks a lot everybody for all your help
Re^4: In a multithreading Perl Code How to Exit one thread while outher thread keeps running ?
by unixmonster (Initiate) on Jul 06, 2009 at 13:15 UTC
    Thanks Corion, Can you throw some more light on "daemonize". Since now you got my exact requirement.