From: Markus Schirp Date: 2009-09-21T02:57:38+09:00 Subject: Re: Thread-safe FileUtils.cd The current working process is a global property of the underlaying system process. A system Process has one currency working directory, not two, or more. You can do your directory / filename calculations, using the absolute directory path, without any race conditions. -- Markus James Coglan wrote: > Hi all, > > I have a build tool that I've written in Ruby that uses this construct to > enter a directory, perform some long-running (several seconds) tasks then > exit back to the original working directory: > > FileUtils.cd(dir) do > # expensive operations > end > > Now I'm trying to write another tool that uses this build library to run > several builds at once in different Threads. Problem is, the FileUtils.cd > commands overlap and conflict with each other, causing the builds to fail. I > have a lot of code already out in production that relies on this directory > being set correctly (users can write hooks into the build system, and these > hooks assume a certain working directory), so I can't remove the cd() call. > > My question is, is there a way of setting the working directory on a > per-thread basis, or is it a global property of the Ruby process that cannot > be made thread-safe? > > Cheers, > James >