in reply to Re: Waiting for multiple filehandles (threads)
in thread Waiting for multiple filehandles

cool script!
where can i find some nice tutorials about threads and using in perl? i understand that the async starts up the code in parallel with other async code blocks..

and why do you have the $done shared? it's not being set to 1 anywhere, so i was just wondering...

but .. your script gives many insights thanks ;-)

--
to ask a question is a moment of shame
to remain ignorant is a lifelong shame

Replies are listed 'Best First'.
Re^3: Waiting for multiple filehandles (threads)
by Mugatu (Monk) on Mar 22, 2005 at 18:11 UTC

    Anyone using threads in Perl should read Things you need to know before programming Perl ithreads.

    Update: I guess I should clarify my position a bit, since I seem to have ruffled BrowserUk's feathers with this post. For me, personally, myself, in my code, on my machine, I agree with merlyn. I might consider using lightweight threads, but Perl's are not. They seem like a bad imitation of a real fork. I think the design of Perl's threads is broken, not the idea of threads in general.

    That being said, I was not trying to persuade anybody not to use threads. If I was, I would have said so. I was simply trying to refer to an article that brings up an important caveat about Perl's threads. As I said later, I think it's important that people know about this caveat. It makes Perl's threads -- as designed and implemented -- distinct from the common understanding of what threads are, and it deserves to be highlighted and explained to folks who are using them.

      Anyone using threads in Perl
      ... won't be dropping their code into production on any box I control. That's another thing to keep in mind. Maybe threads are good for Windows, but on Unix, threads are spelled "f-o-r-k". Forking technology is far better developed and understood and optimized on Unix.

      -- Randal L. Schwartz, Perl hacker
      Be sure to read my standard disclaimer if this is a reply.

      A reply falls below the community's threshold of quality. You may see it by logging in.

      Actually, I think that about 50% of that article is out of date, and another 20% is the author's misunderstanding.


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      Lingua non convalesco, consenesco et abolesco.
      Rule 1 has a caveat! -- Who broke the cabal?

        I think I just heard someone just volunteer to write a new threads tutorial for perlmonks... ;-)

        The main point of the article I posted was that Perl's ithreads are not lightweight. The details may be off, but unless something drastic has changed (which is entirely possible. Please correct me if it has), this basic fact still holds true. It is something everyone who writes threaded code in Perl should know.
        A reply falls below the community's threshold of quality. You may see it by logging in.
Re^3: Waiting for multiple filehandles (threads)
by BrowserUk (Patriarch) on Mar 22, 2005 at 15:44 UTC
    and why do you have the $done shared? it's not being set to 1 anywhere, so i was just wondering

    Because, for clarity, I cut down an existing script which monitors my firewall and modem logs. In the real script, the main thread also traps SIGINT, sets $done true and waits for the threads to terminate before ending.

    I don't know of any good "perl + threads" tutorials. You could do a super search for my posts that contain "use threads", there are quite a few examples now, but be warned, I am still learning what is and is not possible to do and the best ways of doing things. Many of my earlier threads posts contain code which is moe complicated that necessary.

    I'd try and put together some kind of tutorial on them, but I've only use threads and Perl on Win32. I have seen very little information about what works on other platforms, so it would have very limited scope.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    Lingua non convalesco, consenesco et abolesco.
    Rule 1 has a caveat! -- Who broke the cabal?
      ah ok... so i'll just stick perldoc threads.
      thanks anyhow!

      to ask a question is a moment of shame
      to remain ignorant is a lifelong shame

        so i'll just stick perldoc threads.

        That's okay as an API reference, but you did ask about tutorials.

        There is also perlthrtut, but I don't rate it particularly highly.


        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        Lingua non convalesco, consenesco et abolesco.
        Rule 1 has a caveat! -- Who broke the cabal?