Why are reentrant library and system call interfaces good?
There are two approaches to providing system calls and library interfaces that will work with multithreaded programs. One is to simply wrap all the appropriate code with mutexes, thereby guaranteeing that only one thread will execute any such routine at a time. While this approach mostly works, it provides terrible performance. For functions that maintain state across multiple invocations (e.g. strtok() and friends), this approach simply doesn’t work at all, hence the existence of “_r” interfaces on many Unix systems (see below). A better solution is to ensure that library calls can safely be performed by multiple threads at once.