Synchronize calls using the environment variables

* As the underlying C functions are not thread-safe.
* See http://en.cppreference.com/w/cpp/utility/program/getenv.