in reply to Re^4: Your main event may be another's side-show.
in thread Your main event may be another's side-show.

It's about not wanting to be forced to do everything just one way, because the framework is incompatible with any other way of working.

And that's exactly why I like Coro. The other choices for event-driven development take away extremely useful tools (catching exceptions, stack traces) and pollute every tiny bit of code with the need to write the code much differently. Coro only requires that the exact points where blocking might happen be tweaked to make Coro aware of the blocking and those changes are usually pretty easy to make. The rest of your code shows no evidence of Coro being used.

Yes, a single Coro instance won't use multiple cores. That has never been an issue in the projects I've considered Coro for because either they need to scale so I plan on running multiple instances anyway or they don't in which case one core is enough and the other core(s) get used by other stuff. Yes, there are cases where you don't want multiple instances and yet do want to use multiple cores but don't need more cores than are in the one computer you are using, and Coro would not be the best choice in such a constrained situation.

I find that threading can be very useful in the simplest of cases. But having spent years writing multi-threaded code with a group of people who were very good at it, I believe that scaling via threading is nearly a doomed endeavor. My experience is that the vast majority of programmers are quite bad at identifying race conditions. They are even worse at preventing race conditions. And they are worse still at both of those tasks when threads are involved. And even the best programmers can't keep a long-lived, significantly upgraded system free of serious problems associated with using threads.

IME, I'm pretty good at those tasks. And I'd still rather just avoid dealing with them as much as possible. Adding real threads (not what Perl 5 currently calls "threads") means that you have race conditions to consider all over the place. Perl's "threads" came to be because no Perl porter was able to remove the race conditions from trying to use real threads with Perl. So they switched to using threads to emulate fork() but much less efficiently in both memory and CPU required. So I prefer real fork over emulated fork. On Windows, I tend to either use cygwin or use spawn to emulate fork.

I've not used Perl "threads" under Windows even for simple tasks because every time I've tried I've found bugs almost immediately. Lots of people say that is no longer going to happen but then they said that lots of previous times when I still found bugs almost immediately.

I consider Perl "threads" under Windows for simple tasks and so will likely try again at some point. But I strongly avoid threads in a project that will need to scale either to running many instances or (more importantly) to having an extended lifespan of active development and enhancement.

And I've seen many projects start out just fine using threads and then have an ever-increasing set of problems with race conditions, deadlocks, and lack of concurrency. And those problems are rather fundamental.

I'd love to see a very general-purpose framework for preventing race conditions that also prevents deadlocks and reduced concurrency. I don't think one has been invented yet other than the very successful framework of a preemptive-multitasking operating system using processes with segregated resources. When the overhead per process becomes a problem (as can happen with Perl), I think coroutines present the best available long-term solution by allowing one process and one Perl interpreter to handle a large number of simultaneous tasks with only minimal coroutine-specific code. And it looks like Coro is a good implementation of coroutines for Perl.

- tye        

  • Comment on Re^5: Your main event may be another's side-show. (Coro)

Replies are listed 'Best First'.
Re^6: Your main event may be another's side-show. (Coro)
by BrowserUk (Patriarch) on Oct 21, 2010 at 20:03 UTC
    I've not used Perl "threads" under Windows even for simple tasks because every time I've tried I've found bugs almost immediately.

    Really? You've never asked for help. Which makes you a silly billy, because at a rough guess about 80% or more of the "threads bugs" posted here have been user errors. And of the rest, there is usually a relatively simple workaround.

    And I've seen many projects start out just fine using threads and then have an ever-increasing set of problems with race conditions, deadlocks, and lack of concurrency.

    Then post the code and let me fix it for you.

    I'd be fascinated, because as I said somewhere else here yesterday. In 8+ years I've never encountered a deadlock with ithreads.

    Avoiding deadlocks is simple. You just don't write code that creates the situations where they can occur.


    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.
      You've never asked for help. Which makes you a silly billy, because [...] the rest, there is usually a relatively simple workaround.

      Yeah, running into a "panic" at step one with trivial amounts of code makes me shy away from putting my full weight on something. A work-around can be a nice thing. Needing a work-around out of the gate when the code hasn't hardly even started being written is all I need to find a different solution. And you not having noticed me asking for help doesn't actually demonstrate much about how much help I have sought or not.

      In 8+ years I've never encountered a deadlock with ithreads.

      Yeah. iThreads emulate fork(). You don't get deadlocks with just fork() either. When you tie yourself to a framework like iThreads, that is one of the benefits. But since fork() is so much more efficient in memory and CPU than that emulation of it (and is better supported and less buggy), I use the real thing not the emulation.

      - tye        

        Okay. That's what I thought. No real desire to discuss the issues.

        Just another FUD-laden he's-pro-so-I'm-anti rant. You're not as good at them as you used to be.


        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.