lotus

previous page: 5.5. Lightweight process (Programming threads)
  
page up: Threads Programming FAQ
  
next page: 5.7. Protection boundary (Programming threads)

5.6. MT safety (Programming threads)




Description

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

5.6. MT safety (Programming threads)

If some piece of code is described as MT-safe, this indicates that it
can be used safely within a multithreaded program, "and" that it
supports a "reasonable" level of concurrency. This isn't very
interesting; what you, as a programmer using threads, need to worry
about is code that is "not" MT-safe. MT-unsafe code may use global
and/or static data. If you need to call MT-unsafe code from within a
multithreaded program, you may need to go to some effort to ensure
that only one thread calls that code at any time.

Wrapping a global lock around MT-unsafe code will generally let you
call it from within a multithreaded program, but since this does not
permit concurrent access to that code, it is not considered to make it
MT-safe.

If you are trying to write MT-safe code using POSIX threads, you need
to worry about a few issues such as dealing correctly with locks
across calls to fork(2) (if you are wondering what to do, read about
the pthread_atfork(3) library call).

 

Continue to:













TOP
previous page: 5.5. Lightweight process (Programming threads)
  
page up: Threads Programming FAQ
  
next page: 5.7. Protection boundary (Programming threads)