Apr 29
2008

Threads considered harmful

Posted by James Reinders in Programming StyleParallelism Concurrencyconcurrencyabstraction

JReinders

Many have or will shortly embark on the adventure of writing parallel programs. It is, therefore, useful to reflect on what mistakes we might avoid.

My favorite quote is one often attributed to Mark Twain as "History may not repeat itself, but it does rhyme a lot."

Reflecting on a seminal paper (letter) some 40 years ago, "Goto Statement Considered Harmful " by Edsger Dijkstra published in Communicatons of the ACM in March 1968, I see a rhyme in the making.

Dijkstra's letter was short, and included the statement "The go to statement as it stands is just too primitive; it is too much an invitation to make a mess of one's program."

His paper is widely considered to have pushed the industry to a higher level of abstraction - specifically to structured programming (as in block-structured languages).

I still remember vividly those who argued years after his paper was published that eliminating the 'goto' statement would infringe on creativity. In fact, a series of published arguments in favor of the Goto Statement created a response from Dijkstra 20 years after his initial letter entitled "On a somewhat disappointing correspondence" in which he said "The whole correspondence was carried out at a level that vividly reminded me of the intellectual climate of twenty years ago, as if stagnation were the major characteristic of the computing profession, and that was a disappointment."

By now, we certainly know that some programs fail to pass the test of time. Such programs will be re-written because they are too bound to the hardware, embody hard to maintain programming styles, or otherwise express things in a complex manner which can be stated more easily using newer methods.

Today, we have many parallel programs. They are often written using native threads (pthreads , Windows threads, Java threads or Boost threads ).

In the end, they make a mess of a program. Threads are necessary plumbing, but in applications they simply result in programs which will not pass the test of time. Parallel programming, in order to stand the test of time, needs higher level programming methods.

The practical side of me suggests use of any threaded library, OpenMP or TBB. A less practical side encourages looking at new programming languages like Erlang or Haskell. Either way, the more abstact expression of a program will hold up better over time than the lower level of programming associated with native threads.

Are we going to rhyme, and write lots of parallel code with the modern equivalent of the "Goto Statement"?

 

 



Comments (5)Add Comment
...
written by Mark Nelson, April 30, 2008
I think the situation is particularly grim in C/C++ - it is extremely difficult to have a reasonable level of assurance that your program is correct when using threads. Just the inability to control side effects alone means that code inspection for errors is NP++ hard. Automatic proof seemingly impossible.

I agree that threads have to disappear into the infrastructure, just like GOTOs disappeared into the compiled code (but snuck back in via exceptions).

But I also harbor a lingering doubt that Knuth is correct, perhaps parallelism is a swamp we just want to stay out of. Just because it's a bandwagon doesn't mean we should necessarily be jumping on.

- Mark
"The Problem with Threads"
written by James Merritt, April 30, 2008
Edward Lee of the EECS department at Berkeley wrote an interesting report back in 2006: "The Problem With Threads"

The link takes you to a citation page, which also includes a direct link to the 17-page PDF version.

Lee worries about the proliferation of non-deterministic complexity that threads can create, observes that we have been implicitly restricting threads by our programming practices on the one hand and by the relative paucity of true parallel computing environments on the other, and predicts that as soon as computers routinely begin to have more than a couple of processing cores, we will begin to encounter some serious and unpredictable bugs that currently lie dormant in all the threaded code that is already out there.

He does have a prescription for fixing the problem, though.
Edward Lee
written by Mark Nelson, April 30, 2008
Nice paper, of course he echoes what I said in my comment, and we always say "nice paper" when it basically agrees with what you think:

Threads must be relegated to the engine room of computing, to be suffered only by expert technology providers.

My most successful heavily-threaded C++ programs have been based on a fairly strict message passing paradigm, which protects you against a lot of problems - no poking into each other's data. But when you do that, you are almost running as if your threads were separate processes, so you get less of an advantage from the threading model. Faster context-switching, I guess, and a somewhat lighter load on the system.

And of course, if we really believe that the multicore universe is a bigger threat that global warming and the RIAA combined, (don't count me in http://marknelson.us/2007/07/30/multicore-panic/), threading really doesn't do much to help you partition your problems.
Echoes, threats
written by James Merritt, April 30, 2008
"Nice paper, of course he echoes what I said in my comment..." Or you independently echoed what he published 2.5 years ago. Same difference. smilies/wink.gif

"And of course, if we really believe that the multicore universe is a bigger threat that global warming and the RIAA combined..." You forgot Y2K. smilies/cheesy.gif
Robotics may lead the way
written by Kevin Queen, May 02, 2008
Agree that this really is an issue - having seen so many struggle with the problem. Picked up Microsoft Robotics Studio to see what they were up to in the robotics field and was happy to see a framework in place to tackle some of these issues. It is geared to a specific set of applications, but I see in the robotics framework for handling all the different inputs and paralell processing, the kernal for what I would bet becomes a part of their .NET framework. How far it will scale is probably not known yet. But it was good to see someone liberating everyday developers from a world of semaphores thread and management that most are not ready to deal with.

Write comment
You must be logged in to a comment. Please register if you do not have an account yet.

busy

Get your FREE Subscription to Dr. Dobb’s Digest today!

Dobbs Code Talk Quick Poll

This time next year, your most important operating system (host and/or target) will be:

Look Who's Code Talking


Simon Parker
City: Camberwell

Steve Winter
City: Fort Lauderdale

Charles Barest
City: Palm Beach Gardens

Mike C. Baker
City: Murphy

Michael Montvelishsky
City: Cupertino

Ronald Martin
City: Ann Arbor

Dobbs Code Talk Tags

.NET abstraction Ada Adobe Agile Ajax algorithm Algorithmic complexity ALM Analogical reasoning Android Anecdotes Apple Application Development AppStore Architecture and Design ARM Artificial Intelligence Artificial Life Assembler Programming Audio files AVX AWK Banking Bazaar Best Practices Blender Books Brain computer interfacing Build C C Programming C Sharp Cartoon Category theory Cellular automata Clojure Cloud Computing Cobol Cocoa Coder Of The Month Cognition as compression Collaboration Common Process/Frameworks Compilers Computational humour Computational narrative Computational politics Computer Science Computers in art computing pioneers concurrency Conferences Consciousness research Contest Contest140 contests CPlusPlus crime CSharp D Programming Data Centers Databases Debugging Delphi Deployment design Design Patterns Digital Signal Processing Distributed Django Documentation DSL dynamic language Eclipse EDA education Emacs Embedded Systems Encryption engineering Erlang Etymology Excel exception handling Facebook Financial computing Five Questions Flash Flash Lite Flex Forth Fortran Fraud FreeBSD Fun Functional Programming gadgets Games Gender Git gnuplot Go Google Graphics GUI hardware Heron High School High-Performance Computing History Holographic reduced representations HTML5 Humanity Humour Hungarian Notation Identity Inkscape Innovation Intel Interview iPhone J2EE Java JavaFX JavaOne JavaScript language engineering Legal lex LINQ Linux Lisp Literate Programming Logic Programming m4 Mainframes Make Mathematica Mercurial Mesh messaging Metaprogramming Microsoft MID Miscellaneous Musings ML Mobile Software Mobility modeling modular programming multicore Music MVC myblog Natural Language Processing Networking Neural networks newspeak Nokia numerical computing Object Rexx ObjectiveC Office Office 2007 Online spreadsheets OOP Open Source Openaccess publishing OpenBSD OpenSolaris Operating Systems Optimization Oracle Pair Programming Parallelism Concurrency Parsing Pascal Patents Patterns Performance Perl PHP Podcast Pop11 Poplog Privacy Processing Productivity Programming Language Implementation Programming Language One Programming language semantics Programming Languages Programming Style Project Management Prolog Psychology Public understanding of science puzzle Python QA Quantum Computing Quotes Rails Realtime recls Requirements Research practice REST Review RIA rich internet applications Robotics Ruby SaaS Software as a service Scala Schadenfreude Science fiction Screencast Scripting SD Best Practices Search Security Semantic Web Silverlight Snobol SOA social Social Networks Society for the Study of Artificial Intelligence a Software Development Methodology and Management Songs and poems Spending Priorities Spreadsheets SQL Startups Statistics Storage String pattern matching Survey Teaching Testing The Business of Programming The Dobbs Challenge The Future Theory Topology Transhumanism Travel on the Job Twitter Types Unix Upgrade Usability Use Cases USENET User Experience User Interface Design Version Control video virtual machines Virtualization Visual Studio Visual Studio Sponsored Post WCF Web Development Windows Windows 7 Windows Live Wireless WOA WPF X Window System yacc

Subscribe to Dr. Dobbs Newsletter

Email:
Dr. Dobb's Update
Delivered twice a week, Dr. Dobb's Update provides unbiased and objective news, commentary and technical features spanning the entire software development marketplace.

Latest Comments

Jonathan's Last Day at Sun
For the 8 years I worked there, it was fantastic. I worked there under McNealy and I have undying admiration for the guy. I only knew Jonathan periphe...
Implementing Thread Local Storage on OS ...
Back in the day, I did a fair amount of work with PThreads. Wonderful design. Some quirks, but basically really, really nice. Although I wrote a lot ...
More Technonecrophilia with Snobol One-L...
Yeah, It's probably identical except for the (embedded) copy number, I would think. Once it became freely distributable, the copy I've been distribut...
More Technonecrophilia with Snobol One-L...
There's a spitbol-3.7-win.exe at http://code.google.com/p/spitbol/downloads/list . I found it via Dave Shield's blog page http://daveshields.wordpress...
Jonathan's Last Day at Sun
Sadness.

The Latest From Our Member Blogs

How To Select Trainees
Written by Joel Wiesen   
01/27/10
Hiring the right trainee can be harder than hiring a trained programmer.  One approach is described at my website: http://www.aprtestingservices.com/business/lpat/
 
Technical Job Interviews
Written by Keith Kerlan   
01/20/10
What is the best way to interview for software developer positions?  I've been on both sides of the job interviewing table, but have been on the interviewee side of some not too  great inter
 
Timers/timeouts in multi-threaded event-loops
Written by Christof Meerwald   
01/03/10
The traditional way to integrate timeout handling (or timers) in (single-threaded) event loops was to just pass the appropriate timeout value to the select/poll/epoll syscall. While this works fine
 
C vs C++
Written by Issam Lahlali   
12/04/09
I think that the debate "C vs C++" will end when the two langages died, and each one have its advantages and inconvenients, the choice of one instead of another depend on the application c
 
Great Jobs at CISCO
Written by Brent Rogers   
11/30/09
Hello! I am a recruiter at CISCO. We have a number of great jobopportunities at CISCO right now. Please take a look at the job links listedbelow and please send me an updated resume if you are interes
 
OK Labs, ST-Ericsson, and the Mobile/Wireless Ecosystem
Written by Steve Subar   
11/17/09
Two weeks ago, OK Labs and ST-Ericsson announced the selection of OK Labs as ST-Ericsson's mobile virtualization partner. To earn this coveted position, OK Labs prevailed in a rigorous evaluation
 
C++ Ninjas Needed in Santa Clara, California
Written by Brent Rogers   
09/30/09
Hello! I am a recruiter at CISCO. Our PostPath teamin Santa Clara is building a new Email SaaS business at CISCO. We are looking forsenior developers with Zimbra expertise to help us accomplish this t
 
Fighting Fragmentation with Mobile Virtualization
Written by Steve Subar   
09/21/09
Last week Motorola and T-Mobile announced the launch of a new and innovative Android-based smartphone, the Cliq. This attractive, feature-rich slider handset happens to build on a chipset and firmware
 
Insights into Router Design: Unit Testing of Networking Protocols
Written by Rajesh Kumar Venkateswaran   
09/07/09
  Unit testing is a software validation methodology through which a programmer tests individual modules or units of source code. If the programmer has been responsible for developing a networ
 
Insights into Router Design: Implementation of Networking Protocols
Written by Rajesh Kumar Venkateswaran   
09/06/09
  Modern data networking consists of a large number of networking protocols, each of which has its own domain of applicability. Some run on end stations (also called hosts), some on enterp
 
Insights and Innovations in Networking
Written by Rajesh Kumar Venkateswaran   
09/05/09
Networking devices such as routers and switches have evolved quite a bit over the past years, both in the service provider network and in the enterprise. It is a challenge to build these devices, bo
 
reddit threads community
Written by Christof Meerwald   
08/30/09
I have just started a threads community over at reddit to cover topics such as multithreading, concurrency and parallel programming. Feel free to join if you are interested. -- cmeerw.org 
 

The Latest From Dr. Dobbs

DDJ