From: Michal Suchanek Date: 2008-09-10T20:42:17+09:00 Subject: Re: FileUtils.chdir thread safety On 10/09/2008, Robert Klemme wrote: > 2008/9/9 Charles Oliver Nutter : > > > Robert Klemme wrote: > >> > >> 2008/9/9 Mr_Tibs : > >>> > >>> Darn it! It would seem like a good idea. > >> > >> I am not convinced yet. Think about typical scenarios where one > >> thread creates tasks and hands them off to another thread. These will > >> break if every thread has its own idea of current dir. If you use > >> absolute pathnames you do not need a local current dir. This change > >> might even break existing code. I believe we should at least > >> carefully evaluate consequences. > > > > There's no reason threads couldn't inherit a reference to their parent > > thread's cwd, only using a specific one if provided (reverting back to the > > parent's cwd afterward). > > > What does inheriting change about my argument? Even with inheriting > you can send relative path names from one thread to another which do > not have the same cwd. My point is, that since safe programming > requires either transferring absolute paths or relying on having a > single cwd per process (which is traditionally the case) there is > little need for this. Yes, thread-local chdir sort of breaks some traditional semantics. However, with multithreaded application you either do not chdir and keep the same cwd everywhere, or you do chdir and then you must know what you are doing which includes reading the docs on your chdir. If you do not know what you are doing you will get into trouble one way or another because it is not safe to assume that chdir will read your mind and do exactly the right thing. As mentioned earlier there are already problems with the current behaviour anyway. Also this could possibly be an option - load thread/chdir and now you can control if your thread cwds are bound together or not. Thanks Michal