I was wondering if I could instantiate two different Goroutines, each of them with their own working directory using os.Chdir
, without modifying the working directory of the main routine.
...
// Go routine A
go func() {
os.Chdir("dir_a/")
} ()
// Go routine B
go func() {
os.Chdir("dir_b/")
} ()
...
So far, the avobe code does not prevent the main thread to change its working directory to "dir_b/", and I am sure it also has a serious risk of a racing condition between each Goroutine.
Is it possible to have two different goroutines with different working directories?
No. Your application has just one working directory.