Team LiB
Previous Section Next Section

Final Thoughts About Threading

The main thing to remember about threading is that it necessitates a different mindset. It requires you always look out for worst-case scenarios, both during design and debugging. After each line of multithreaded code you write, ask yourself, "Suppose this thread yielded to another thread right here—would anything bad happen?" Write one more line of code and then ask yourself the same question again. Code defensively—be an eternal pessimist and expect disaster so you can plan for it. But if you're careful, multithreaded development becomes quite doable. Don't kid yourself that it will be easy: Multithreaded bugs tend to be more subtle than most other errors, so you have to be extra vigilant to find and fix them. But don't be unreasonably afraid of threading, either. Millions of successful multithreaded programs have been written over the years, and if you set your mind to it, your program can be one, too.


Team LiB
Previous Section Next Section