This is review of the 13th chapter from the book-”Clean Code: A Handbook of Agile Software Craftsmanship” by Robert C. Martin.
Concurrency increases the complexity of the program many-folds. Accordingly, the challenges to keep concurrency riddled code clean and efficient also increases exponentially.
To code well for concurrency- familiarize yourself with classical problems such as
Producer-Consumer
Readers-Writers
Dining Philosophers
Some other worthy recommendations are
Keep your concurrency-related code separate from other code.
Take data encapsulation to heart; severely limit the access of any data that may be shared.
Attempt to partition data into independent subsets than can be operated on by independent threads, possibly in different processors.
Know your library.
Know your execution models
Use copies of data
Avoid using more than one method on a shared object.
Keep your synchronized sections as small as possible.
Think about shut-down early and get it working early.
Don’t ignore a failure just because the tests pass on a subsequent run.
Do not ignore system failures as one-offs.
Get your non-threaded code working first
Make your thread-based code especially pluggable so that you can run it in various configurations.
Make your threaded code tunable.
Run with more threads than processors
Run your threaded code on all target platforms early and often.
Instrument your code to try and force failures
For review of other chapters- please see this post.


Pingback: Book Review: Clean Code: A Handbook of Agile Software Craftsmanship | Technology Cafe