Make environment variables thread-safe

The C functions `setenv()` and `getenv()` are not thread-safe so we protect them with a mutex in a multi-VM environment.

Also a line of test added for VMPort's type.