From: Charles Oliver Nutter Date: 2008-09-12T05:01:00+09:00 Subject: Re: FileUtils.chdir thread safety Charles Oliver Nutter wrote: > Michal Suchanek wrote: >> If you allow global chdir that's technically chnging the cwd for other >> threads. >> >> I had a vague idea that there could be an option that controls if cwd >> should be emulated ( saved/restored on thread switch or restored for >> syscalls that need it) or the global cwd should be used. > > Changing it on thread switch would probably be necessary for MRI, but > not really necessary or possible on JRuby since threads run in parallel. > But by the same token, I'm not certain any JRuby support for per-thread > CWD would be able to handle calls out to 'ls' and friends, since even > the best fakery we can do to make File APIs have a per-thread CWD would > still not affect the system calls used to launch external processes... Actually I suppose there is a way; have all process launches acquire a lock during the process launch, so they can atomically chdir for the process quickly and then chdir back, letting the child run. Kinda hacky though, and I'm not sure what effect process-level chdir would have on the JVM. - Charlie