Making getenv more multi-threading--robust?

Torvald Riegel triegel@redhat.com
Thu Sep 13 19:44:00 GMT 2012


On Thu, 2012-09-13 at 12:56 +0200, Stephan Bergmann wrote:
> Though getenv is generally known to not be thread-safe, glibc already 
> contains measures to make concurrent calls to setenv etc. thread-safe, 
> so I wonder whether something like the attached 
> 0001-Prevent-races-when-getenv-walks-__environ-while-sete.patch would 
> make sense.  While this would not solve my problems with 
> (cross-platform) LibreOffice, it would help prevent glibc getenv crashes 
> as demonstrated by the little program in the patch's commit message.

If different threads frequently call getenv, this could decrease
performance due to cache misses and/or contention on the lock.

*If* this is problem that we face in practice, then we can likely
synchronize differently in getenv (i.e., return consistent information
without any special ordering guarantees wrt setenv calls).  In that
case, I can help with that.

Torvald



More information about the Libc-alpha mailing list