Dr. Dobb's is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.

Channels ▼

James Reinders

Dr. Dobb's Bloggers

Threads considered harmful

April 28, 2008

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"?



Related Reading

More Insights

Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.