I have a question using Dir.chdir. Is the current working directory for
a program unique to thread or to the program? My multithread program is
experiencing problems. It seems that a Dir.chdir in one thread changed
the working directory of another thread. Is there a “thread-safe” chdir?
An OS issue. The notion of the current directory
is per-process.
Not possible to do what you want unless you
support it yourself… e.g., do some syncing at
the same time you change dirs.
mutex.synchronize do
Dir.chdir(newdir) do
# code…
end
end
But if you were going to do that, it might be
almost as easy just to keep the dir info for
each thread and stick it on the front of each
filename or whatever.
Hal
···
----- Original Message -----
From: “Xiangrong Fang” xrfang@hotmail.com
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Wednesday, August 06, 2003 10:49 PM
Subject: Working directory in thread
I have a question using Dir.chdir. Is the current working directory for
a program unique to thread or to the program? My multithread program is
experiencing problems. It seems that a Dir.chdir in one thread changed
the working directory of another thread. Is there a “thread-safe” chdir?
At Thu, 7 Aug 2003 12:49:31 +0900, Xiangrong Fang wrote:
I have a question using Dir.chdir. Is the current working directory for
a program unique to thread or to the program? My multithread program is
experiencing problems. It seems that a Dir.chdir in one thread changed
the working directory of another thread. Is there a “thread-safe” chdir?
CWD is a process resource. There is no “thread-safe” way, in
general.