[Return to Bookshelf] [Contents] [Previous Section] [Next Section] [Index] [Help]


3.2 Threads and Libraries

Because multithreaded programming has only recently become common, many existing code libraries are incompatible with threads. Many of the traditional C run-time library routines, for example, maintain state across multiple calls using static storage. This storage can become corrupted if routines are called from multiple threads at the same time. Even if the calls from multiple threads are serialized, code that depends upon a sequence of return values might not work. For example, the getpwent(2) routine returns the entries in the password file in sequence. If multiple threads call getpwent repeatedly, even if the calls are serialized, no thread will see all entries in the password file.

Library routines might be compatible with multithreaded programming to different extents. The important distinctions are thread safety and thread reentrancy.