While ensuring thread safety may be impossible we could improve robustness by using thread local storage for the result of the rcutils_get_env function.
This would also be a good time to refactor every part of the code reading environment variables to use this function
Related ticket ros2/rcl#97