Working directory in thread

X

Xiangrong Fang

Hi

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?

Thanks!
 
H

Hal E. Fulton

----- Original Message -----
From: "Xiangrong Fang" <[email protected]>
To: "ruby-talk ML" <[email protected]>
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?

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
 
N

nobu.nokada

Hi,

At Thu, 7 Aug 2003 12:49:31 +0900,
Xiangrong said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top