Working directory in thread

Discussion in 'Ruby' started by Xiangrong Fang, Aug 7, 2003.

  1. 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!

    --
    Xiangrong Fang <>
    Xiangrong Fang, Aug 7, 2003
    #1
    1. Advertising

  2. ----- Original Message -----
    From: "Xiangrong Fang" <>
    To: "ruby-talk ML" <>
    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

    --
    Hal Fulton
    Hal E. Fulton, Aug 7, 2003
    #2
    1. Advertising

  3. Xiangrong Fang

    Guest

    Hi,

    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.

    --
    Nobu Nakada
    , Aug 7, 2003
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Charles A. Lackman

    Terminating a thread from the main thread

    Charles A. Lackman, Dec 9, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    1,541
    Herfried K. Wagner [MVP]
    Dec 9, 2004
  2. pawo
    Replies:
    0
    Views:
    490
  3. Stephen Miller
    Replies:
    3
    Views:
    3,966
    Stephen Miller
    Jul 2, 2004
  4. Johanna
    Replies:
    0
    Views:
    603
    Johanna
    Oct 13, 2004
  5. Priyanka AGARWAL
    Replies:
    9
    Views:
    9,972
    Gordon Beaton
    May 25, 2004
Loading...

Share This Page