This preview shows page 1. Sign up to view the full content.
Unformatted text preview: fer from system to system. Thus, the “ r” interface should not be used unless absolutely necessary. 11.7 Other Synchronization Errors
Even if we have managed to make our functions thread-safe, our programs can still suffer from subtle synchronization errors such as races and deadlocks. 11.7.1 Races
A race occurs when the correctness of a program depends on one thread reaching point Ü in its control ﬂow before another thread reaches point Ý . Races usually occur because programmers assume that threads will take some particular trajectory through the execution state space, forgetting the golden rule that threaded programs must work correctly for any feasible trajectory. An example is the easiest way to understand the nature of races. Consider the simple program in Figure 11.30. The main thread creates four peer threads and passes a pointer to a unique integer ID to each one. 11.7. OTHER SYNCHRONIZATION ERRORS 597 Each peer thread copies the ID passed in its argument to a local variable (line 2...
View Full Document
- Spring '10
- The American