I just found something related to my problem, this is about perl but I guess it is the same. http://search.cpan.org/~jdhedden/thread ... threads.pm
Current working directory
On all platforms except MSWin32, the setting for the current working directory is shared among all threads such that changing it in one thread (e.g., using chdir()) will affect all the threads in the application.
On MSWin32, each thread maintains its own the current working directory setting.
Currently, on all platforms except MSWin32, all system calls (e.g., using system() or back-ticks) made from threads use the environment variable settings from the main thread. In other words, changes made to %ENV in a thread will not be visible in system calls made by that thread.
To work around this, set environment variables as part of the system call. For example:
my $msg = 'hello';
system("FOO=$msg; echo \$FOO"); # Outputs 'hello' to STDOUT
On MSWin32, each thread maintains its own set of environment variables.