Practical Unix Programming: A Guide to Concurrency, Communication, and Multithreading
By Kay A. Robbins, Steven Robbins
©1996 Prentice Hall PTR
This is a positively brilliant textbook that tackles the most challenging issues facing software developers in writing code for a multitasking environment. What sets the book apart from its peers is its hybrid approach combining theory and practical examples to quickly give the reader a comprehensive view of the topic.
Put simply, concurrency is the state of having more than one process going at the same time sharing one or more resources. While rigorous scientific theory on the subject is critical, practical experience for many people is the best way to internalize the subtleties of the topic. And the subtleties are numerous, because bugs in concurrent programs are often times not reproducible.
When writing concurrent programs, the difficulty arises from the fact that the operating system schedules all tasks, and we don't know what other tasks are doing or when any given tasks start or stop. In preemptive multitasking systems like Unix, our process could be halted literally anywhere and another process that uses one of the same resources could be started. If multiple processes are trying to write something to the end of the same file, and the first is halted after determining the location of the end of the file but before writing to it, then it could conceivably write over anything that was written in between the time it was halted and when it was restarted. This particular problem has an easy solution, but it's just the tip of the iceberg for what kind of unexpected problems concurrency can cause.
Practical Unix Programming tackles this tricky subject by first laying out some basic theory on each topic, then describing the implementation of this theory using POSIX.1, and finally presenting full-blown examples. Where POSIX is not sufficient, Spec 1170 is used, or if even more functionality is needed System V Release 4. The result is that the reader gets a good theoretical understanding that is also portable in the most practical way.
To make maximum use of this book, the user must have a firm grasp on ANSI C and moderate experience working on a Unix-like operating system. Possibly a good complement to Advanced Unix Programming. Here are the major sections of the book:
- What Is Concurrency?
- Programs and Processes
- Project: The Token Ring
- Project: Timers
- Project: Cracking Shells
- Critical Sections and Semaphores
- POSIX Threads
- Thread Synchronization
- Project: The Not Too Parellel Virtual Machine
- Client-Server Communication
- Project: Internet Radio
- Remote Procedure Calls
- Project: Tuple Space
Appendix B: UICI Implementation