When you design and code a multithreaded program, consider the following problems and accommodate or eliminate each as appropriate:
Program complexity is the most significant problem to consider in any multithreaded programming effort. Although using threads can simplify the coding and designing of a program, a certain level of expertise is required to be sure that the synchronization and interplay among threads is correct. This level of expertise is higher than for most single-threaded programs.
Race conditions from programming errors may cause unpredictable and erroneous program behavior. Section 3.6.2 discusses race conditions in more detail.
Deadlocks from programming errors can cause two or more threads to be blocked from executing indefinitely. Section 3.6.3 discusses deadlocks in more detail.
Priority inversion prevents high-priority threads from executing when interdependencies exist among three or more threads of different priorities. Section 3.5.1 discusses priority inversion in more detail.
If a thread calls a routine or library that is not equipped to deal with threads, use the global locking mechanism to prevent conflicts with other threads using the same routine or library. Section 3.2.1 discusses nonreentrant software in more detail.