The ntohl function converts a 32 bit integer from

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

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 flow 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

Ask a homework question - tutors are online