Slashdot Mirror


Threads Considered Harmful

LBR9 writes "James Reinders compares native threads with the goto statement so famously denounced 40 years ago by Edsger Dijkstra. Paraphrasing Dijkstra, he says they both 'make a mess of a program,' and then argues in favor of a higher level of abstraction. A couple of people commenting on the post question whether or not we should be even be treading into the 'swamp of parallelism,' echoing the view recently espoused by Donald Knuth."

13 of 266 comments (clear)

  1. No threads? by Anonymous Coward · · Score: 5, Funny

    Alright, then all responses to this article need to fall under this one post.

  2. How about "C++ threads considered harmful"? by krog · · Score: 4, Insightful
  3. I'm All For Getting Rid Of Threads, But... by rsmith-mac · · Score: 3, Informative

    I'm all for getting rid of threads, but what are you going to replace them with? Traditional functional languages may be the most obvious solution, but they're also among the most impractical of solutions. Is there anything else out there that can replace threading needs, without throwing out the book on programming? It seems like what we need hasn't been invented yet.

  4. I disagree with both this guy AND Dijkstra by halivar · · Score: 4, Interesting

    Goto's and global variables are not inherently wrong or evil. They are tools. Granted, they are tools that, if misused, will wreak havoc on your code's stability and maintainability. The same could be said, however, for pointers. Threads are dangerous, and require special care. This is not a reason to avoid them; it is only a reason to be incredibly careful with them.

    Use the best tool for the job, regardless of whether your CS professors demonized it or not.

  5. Not really news by AKAImBatman · · Score: 5, Insightful

    Threads have been considered a "bad idea" by the CompSci profession for a little while now. So there is definitely nothing new about the author's statements. That being said, there is a fundamental difference between Dijkstra's paper 40 years ago and this summary: Dijkstra started his paper by holding up examples of better practices. Only after establishing their existence did he go on to suggest that the GOTO keyword was "too primitive" to be of practical use in software development.

    The author of this "article" (and I use the term loosely) doesn't really present such options. He hand waves a few work-in-progress solutions at the end, compares threads to GOTO statements, then asks the readers to fill in the (rather sizable) blanks.

    Long story short, it's a good topic of discussion, but the comparison to Dijkstra's famous paper is just an advertising point. Nothing more, nothing less.

  6. processes by mkcmkc · · Score: 3, Interesting

    Well, for starters, there's processes, which were invented in the 1960s. These may not handle every case, but in my experience they'd cover 95+%...

    --
    "Not an actor, but he plays one on TV."
  7. Re:Slowaris caused threading by LizardKing · · Score: 3, Insightful

    Complete crap. Threads solve a number of programming problems much more elegantly than forked processes and sharing data through some IPC mechanisms. Anecdote time: a stock price system I worked on. The first generation used separate processes for a single writer and a large number of readers, with shared memory for interprocess communication. This was switched to a threaded implementation for the second generation, which was faster, even though it was using the old LinuxThreads implementation, and more easily maintained as the pthreads API is much richer than IPC ones.

  8. Re:How about "C++ threads considered harmful"? by ezzzD55J · · Score: 3, Funny

    (in C++ even more, when a String object is declared on stack and freed in its constructor) Sounds a bit soon :)
  9. Web server w/o processes OR threads... by Dr.+Manhattan · · Score: 3, Informative

    Unix's select/poll mechanism avoids all that. See, e.g., here.

    --
    PHEM - party like it's 1997-2003!
  10. That's not disagreeing with Dijkstra by Anonymous Coward · · Score: 4, Insightful

    I know nobody born in the last 30 years has bothered to read his memo, but he doesn't pretend gotos are "evil". Just that people should adopt structured control flow structures instead. Meaning, design and use languages with such advanced features as "if/else" statements, and "while" loops, and "functions". Goto considered harmful was written in a time when most people were not using the fancy new languages that offered these features, and he was suggesting that they do so, in order to improve the quality of their code.

    Unless you seriously think people should use gotos instead of loops and if/else statements, then you don't disagree with Dijkstra.

  11. chickens by Viking+Coder · · Score: 3, Funny

    Q) Why did the multithreaded chicken cross the road?
    A) to To other the side. get the

    --
    Education is the silver bullet.
  12. Fancy programming languages are NOT the solution. by ulatekh · · Score: 4, Interesting

    I'm tired of reading replies to this article that evangelize some fancy-schmancy high-level solution. I wonder if these advocates have ever tried writing production code in such an environment.

    Let me give you a wonderful example of when theory simply doesn't meet reality.

    Recently, I wrote a bunch of multi-threaded code for a next-generation asymmetric-multiprocessing game console that shall remain nameless. Its operating system has a wonderful complement of synchronization features. There's the usual mutex lock/unlock, and the usual condition signal/wait, but there are also event queues (queues of generic events that can be passed between threads running on different types of processors), lightweight mutexes/conditions, spinlocks, semaphores, reader/writer locks, and so on and so on. Truly a rich palette from which one can paint a wonderfully synchronized multi-threaded application! I then proceeded to try to rewrite a key section of our code in a very multi-threaded way.

    The problem was, the first version of this code added NINETY milliseconds per frame to our main thread. A profile showed that nearly all of the extra time was spent in the operating system's synchronization features.

    After much rewriting and much pain, I stopped using all of the operating system's synchronization features, and used processor-level atomic operations instead, and finally, the extra code accounted for only FOUR milliseconds per frame in our main thread (with the rest of the time successfully farmed out to separate threads).

    I challenge anyone with a fancy-schmancy automatic concurrency solution to demonstrate that it doesn't have this problem.

    --
    "Once we've identified and embraced our sickness, we'll have strength...and that's when we get dangerous." - John Waters