Summary

We began this chapter by focusing on the key concepts of concurrency, atomicity, and the need to recognize critical sections and protect them. Locking is a typical way to achieve this; the pthreads API set provides the powerful mutex lock to do so. However, using locks, especially on large projects, is fraught with hidden problems and dangers—we discussed useful Locking guidelines, Deadlock and its avoidance.

This chapter then went on to guide the reader in the usage of the pthreads mutex lock. A lot of ground was covered here, including various mutex attributes, the importance of recognizing and avoiding the priority inversion issue, and variations on the mutex lock. Finally, we covered the need for and usage of the condition variable (CV) and how it can be used to efficiently facilitate inter-thread event notification.

The next chapter is the final one in this trilogy of chapters on multithreading; in it, we shall focus on the important issues of thread safety (and thread-safe APIs), thread cancellation and cleanup, mixing signals with MT, a few FAQs and tips, and look at the pros and cons of the multiprocess vs the  multithreaded model.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset