getenv not thread safe

Michael Eager eager@mvista.com
Tue Feb 24 16:33:00 GMT 2004


Ulrich Drepper wrote:
> 
> Michael Eager wrote:
> > On an SMP system, it's possible that getenv may be walking the
> > environment while setenv is reallocating it.
> 
> Then don't do this.  POSIX explicitly says the *env functions are not
> thread safe.

Then perhaps the glibc documentation should not claim to be thread safe:

   Environment Access

   The value of an environment variable can be accessed with the getenv 
   function. This is declared in the header file stdlib.h. All of the 
   following functions can be safely used in multi-threaded programs. 
   It is made sure that concurrent modifications to the environment do 
   not lead to errors. 

http://www.gnu.org/software/libc/manual/html_node/Environment-Access.html#Environment%20Access


--
Michael Eager     eager@mvista.com	408-328-8426	
MontaVista Software, Inc. 1237 E. Arques Ave., Sunnyvale, CA  94085



More information about the Libc-alpha mailing list