Remove all uses of #chdir in threaded code