👨‍💻
Software Engineering
Clean Code: Agile Software Craftsmanship
Clean Code: Agile Software Craftsmanship
  • Clean Code
  • 1: Clean Code
    • There Will Be Code
    • Bad Code
    • The Total Cost of Owning a Mess
    • Schools of Thought
    • We are Authors
    • The Boy Scout Rule
    • Prequel and Principles
    • Conclusion
  • 2: Meaningful Names
  • 3: Functions
  • 4: Comments
  • 5: Formatting
  • 6: Objects and Data Structures
  • 7: Error Handling
  • 8: Boundaries
  • 9: Unit tests
  • 10: Classes
  • 12: Emergence
  • 13: Concurrency
    • Why Concurrency?
    • Challenges
    • Concurrency Defense Principles
    • Know Your Library
    • Know Your Execution Models
    • Beware Dependencies between Synchronized Methods
    • Keep Synchronized Sections Small
    • Writing Correct Shut-Down Code is Hard
    • Testing Threaded Code
    • Conclusion
Powered by GitBook
On this page
  1. 13: Concurrency

Writing Correct Shut-Down Code is Hard

Graceful shutdown can be hard to get correct.

Examples

Imagine a system where a parent spawns child threads

  • The parent waits for all to finish before it shuts down.

  • What if one of the spawned threads is deadlocked?

  • The parent will likely wait forever.

A similar system is instructed to shut down.

  • The parent thread tells spawned child threads to abandon their tasks and finish.

  • What if two children were operating as a producer/consumer pair?

  • Producer receives the signal and shuts down.

  • The consumer might be blocked waiting for the producer and is in a blocked state.

Recommendation:

Think about shut-down early and get it working early.

It's going to take longer than you expect.

Review existing algorithms because this is probably harder than you think.

PreviousKeep Synchronized Sections SmallNextTesting Threaded Code

Last updated 9 months ago