in reply to Thread Exit Status

First off, you don't want to join threads in the same order that you created them. Probably. Use threads->list(threads::joinable) to find the ones that are done. The downside is figuring out how to wait until some thread is ready (maybe yield()?) This way, you deal with the threads that are ready instead of waiting until the "next" thread is done. Maybe the first thread is grabbing something from a server that's down - by the time it times out, the rest of your threads are already done.

Second, check the threads documentation. It says pretty plainly how to get the return from a thread. That is, $thr->join returns whatever the thread sub returned.

Personally, I'd lean toward using AnyEvent::HTTP - there's a fairly good chance you'll get better performance without threads than with them.

FYI, I use Coro, Coro::LWP (and thus LWP, and AnyEvent::HTTP together to good effect already. In some ways, it's easier than perl threads, in others more complex.

Replies are listed 'Best First'.
Re^2: Thread Exit Status
by BrowserUk (Patriarch) on Dec 15, 2011 at 01:00 UTC
    First off, you don't want to join threads in the same order that you created them.

    Why not when the only other thing he's got to do is wait for another thread, or exit?

    Even if all 9 other threads finish before the first one he attempts to join, it'll only take .04 of a second to join the other 9 before he exits.

    It only becomes important to join threads in the order they finish if you've got another thread to start as soon as the first is finished. In which case using a pool of threads is better anyway.

    The downside is figuring out how to wait until some thread is ready (maybe yield()?)

    yield is a very bad bad way of waiting. Yielding in a tight loop will consume prodigious amount of cpu. It is the ultimate busy loop.

    there's a fairly good chance you'll get better performance without threads than with them.

    I'll rise to that challenge. Will you?


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

    The start of some sanity?