Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Are there any canonical sources for learning how to structure multi-threaded programs? Even with all the concurrency utility classes that Java provides I'm having a hard time properly structuring multi-threaded programs. Whenever threads are involved my code becomes very brittle, any little change can potentially break the program because the code that jumps back and forth between the threads tends to be very convoluted.

share|improve this question

closed as off-topic by durron597, Ixrec, MichaelT, gnat, ratchet freak Apr 24 '15 at 14:13

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions asking us to recommend a tool, library or favorite off-site resource are off-topic for Programmers as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it." – durron597, Ixrec, Community, gnat, ratchet freak
If this question can be reworded to fit the rules in the help center, please edit the question.

I'm keen to see the answers here because I couldn't find any (for Delphi or in general). I ended up using diagrams based on electrical timing diagrams, which worked but were hard for other programmers to understand (samples at But my code was still fairly brittle - it was hard for other people to make changes without the unit tests failing. And I had to extend DUnit for MT use - I hope JUnit at least does MT testing well. – Мסž Feb 25 '11 at 5:07
@moz: UML Sequence Diagram can be useful for documentation and discussion purposes. This diagram is easy to make using hand-drawing, simple applications, or even text editor. – rwong Feb 27 '11 at 3:46
@rwong: sequence diagrams are basically simplified timing diagrams. I found that as the code got more complex sequence diagrams stopped being useful well before timing diagrams. – Мסž Feb 27 '11 at 20:52
up vote 3 down vote accepted

If you haven't already, I highly recommend reading "Java Concurrency in Practice". While it doesn't directly solves your problem, it'll certainly provide helpful background on Java Concurrency, and you'll be able to better structure your programs.

share|improve this answer

Look at the GNU/Linux shell pipelines for hints as to how to structure a multi-threaded program.

The pipeline concept of a loop which does reading-working-writing is proven, established, well understood and easy to implement in threads instead of processes.

(I used to write software for radars and sonars, where "real time" actually meant real time.)

Follow the pipeline design pattern. It's how good, robust software is written.

share|improve this answer

There's a monogram called Structured Development of Parallel Programs, by Susanna Pelagatti. Despite being old (1998 - and hence out of print) the way you structure parallel programs hasn't actually changed much, just the tools available for scheduling and manipulated work units have. The methodology described in the book is still pretty useful.

share|improve this answer

Study ACE framework - it's a great way to learn design patterns and even grab reusable components for concurrent programming and communication. It addresses many areas of concern for multithreaded programming: organizing and communicating between your threads, synchronizing data access, and performing IO. And it take good care of performance issues too.

share|improve this answer

I would suggest "Pattern-Oriented Software Architecture Volume 2: Patterns for Concurrent and Networked Objects".

share|improve this answer

Check out erlang, it does concurrency quite well, but takes a very different approach to it, by being a functional language with a shared nothing model it removes the need for locks (mostly)

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.