lotus

previous page: 11. (DCE?, POSIX) Why does everyone tell me to avoid asynchronous cancellation? (Programming threads)
  
page up: Threads Programming FAQ
  
next page: 12.1. (DCE, POSIX, UI) When should I use thread-safe "r" library calls? (Programming)

12. Why are reentrant library and system call interfaces good? (Programming threads)




Description

This article is from the Threads Programming FAQ, by Bryan O'Sullivan bos@serpentine.com with numerous contributions by others.

12. Why are reentrant library and system call interfaces good? (Programming threads)

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.

 

Continue to:













TOP
previous page: 11. (DCE?, POSIX) Why does everyone tell me to avoid asynchronous cancellation? (Programming threads)
  
page up: Threads Programming FAQ
  
next page: 12.1. (DCE, POSIX, UI) When should I use thread-safe "r" library calls? (Programming)