Practical Unix Programming: A Guide to Concurrency, Communication, and Multithreading
By Kay A. Robbins, Steven Robbins
©1996 Prentice Hall PTR
ISBN: 0-13-443706-3

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:

    I Fundamentals

  1. What Is Concurrency?
  2. Programs and Processes
  3. Files
  4. Project: The Token Ring
  5. II Asynchronous Events

  6. Signals
  7. Project: Timers
  8. Project: Cracking Shells
  9. III Concurrency

  10. Critical Sections and Semaphores
  11. POSIX Threads
  12. Thread Synchronization
  13. Project: The Not Too Parellel Virtual Machine
  14. Communication

  15. Client-Server Communication
  16. Project: Internet Radio
  17. Remote Procedure Calls
  18. Project: Tuple Space
  19. Appendix A: UNIX Fundamentals

    Appendix B: UICI Implementation