This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: Making getenv more multi-threading--robust?
- From: Torvald Riegel <triegel at redhat dot com>
- To: Stephan Bergmann <sbergman at redhat dot com>
- Cc: libc-alpha at sourceware dot org
- Date: Thu, 13 Sep 2012 21:43:58 +0200
- Subject: Re: Making getenv more multi-threading--robust?
- References: <5051BBEF.4080401@redhat.com>
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